Custom Path Stairs

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
onekk
Veteran
Posts: 6208
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: How would I make a simple path array script?

Post by onekk »

It depends on what you are using to derive the step orientation, if you use my code, it calculate the distance between the starting point and the endign point, so an "internal wire length " is much sorter than the "external wire length", for curve it generate correct steps, as you are following a sort of "radius", for angled the code is not correct, maybe using the tangent and calculate the direction 90 degree from the tangent will gave more correct results.

The base was a circular or better was a bspline.


Maybe analizing the derivative and with some if clauses or othee means of decision a more correct approach could be found.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
ABeton
Posts: 150
Joined: Tue Sep 03, 2019 6:39 pm

Re: How would I make a simple path array script?

Post by ABeton »

paullee wrote: Thu Apr 29, 2021 1:38 pm Looks promising!

Inspiring indeed! I had a few features I wanted to implement in Arch Stairs earlier but occupied by something else. And stuck with thinking for a more flexible workflow of doing custom stairs. Now it seems you are getting .there :D
Thank you! I found the forum link where you posted about your progress with the stairs before, you did some really great work, wow!! I did not know that you made stairs modular, there is no info in the wiki about it.

Anyway now when I saw how the current Arch Stairs work, I guess I could focus on just making these stairs as another module for the existing Arch Stair tool. If we had 3 different ways to make stairs in FreeCAD, that would be perfect. I also saw how stairs are made in Archicad, but I think it is too complex to make, and in FreeCAD probably not necessary.

Types of stairs we could have in FreeCAD according to me:

1. Normal stairs as we already have them, they are very good, maybe some things can be improved(railing perhaps) but still great work
2. Curved stairs which I plan to make, they could have various curved shapes and also irregular forms(but I will focus on simplicity)
3. Stairs made out of arrays of customised step objects(we create a customised step object using Part Design for example), this is actually already possible so perhaps we do not even need a dedicated command
4. Stairs made out of 2D plans, Yorik mentioned this idea before and it would be cool to have the option

If we had all these stair options, we could probably consider the stair tools pretty much complete in my opinion. I will focus on curved stairs now(when I find time to do it) and wrap them up. After that I will see about the 2 last types of stairs I mentioned. What do you think about all this, any ideas or suggestions?
onekk wrote: Thu Apr 29, 2021 3:27 pm It depends on what you are using to derive the step orientation, if you use my code, it calculate the distance between the starting point and the endign point, so an "internal wire length " is much sorter than the "external wire length", for curve it generate correct steps, as you are following a sort of "radius", for angled the code is not correct, maybe using the tangent and calculate the direction 90 degree from the tangent will gave more correct results.

The base was a circular or better was a bspline.


Maybe analizing the derivative and with some if clauses or othee means of decision a more correct approach could be found.

Regards

Carlo D.
I will try to do it with the tangent and a 90 degree rotation. I already have that somewhere in my old code so I think I will be able to reuse it and combine with what I already have.
paullee
Veteran
Posts: 5120
Joined: Wed May 04, 2016 3:58 pm

Re: How would I make a simple path array script?

Post by paullee »

ABeton wrote: Fri Apr 30, 2021 2:05 pm Thank you! I found the forum link where you posted about your progress with the stairs before, you did some really great work, wow!! I did not know that you made stairs modular, there is no info in the wiki about it.
My bad, still not learned editing the wiki :)
ABeton wrote: Fri Apr 30, 2021 2:05 pm 3. Stairs made out of arrays of customised step objects(we create a customised step object using Part Design for example), this is actually already possible so perhaps we do not even need a dedicated command
4. Stairs made out of 2D plans, Yorik mentioned this idea before and it would be cool to have the option
Agree that would be pretty much need :)

And there was an idea discussed that Stairs just output the 'profile' of stairs - that is the most tedious and repetitive part - and/or tread/riser etc. Then can, e.g. sweep this profile along a path to produce the stairs as desired (some demos in previous thread).

ABeton wrote: Fri Apr 30, 2021 2:05 pm 4. Stairs made out of 2D plans, Yorik mentioned this idea before and it would be cool to have the option
This idea is cool and powerful.

And thanks for @onekk's contribution.
onekk wrote: Ping
User avatar
onekk
Veteran
Posts: 6208
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: How would I make a simple path array script?

Post by onekk »

Not a problem, ping me if you want some other suggestions.

I model mostly with Scripting, so I have learn some "intricated ways" to do things, if they are no too intricated and could be useful to someone other than me, i will be very happy to contribute.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
ABeton
Posts: 150
Joined: Tue Sep 03, 2019 6:39 pm

Re: How would I make a simple path array script?

Post by ABeton »

paullee wrote: Fri Apr 30, 2021 6:20 pm
ABeton wrote: Fri Apr 30, 2021 2:05 pm Thank you! I found the forum link where you posted about your progress with the stairs before, you did some really great work, wow!! I did not know that you made stairs modular, there is no info in the wiki about it.
My bad, still not learned editing the wiki :)
ABeton wrote: Fri Apr 30, 2021 2:05 pm 3. Stairs made out of arrays of customised step objects(we create a customised step object using Part Design for example), this is actually already possible so perhaps we do not even need a dedicated command
4. Stairs made out of 2D plans, Yorik mentioned this idea before and it would be cool to have the option
Agree that would be pretty much need :)

And there was an idea discussed that Stairs just output the 'profile' of stairs - that is the most tedious and repetitive part - and/or tread/riser etc. Then can, e.g. sweep this profile along a path to produce the stairs as desired (some demos in previous thread).

ABeton wrote: Fri Apr 30, 2021 2:05 pm 4. Stairs made out of 2D plans, Yorik mentioned this idea before and it would be cool to have the option
This idea is cool and powerful.

And thanks for @onekk's contribution.
onekk wrote: Ping
I saw the profile out of stairs idea, it looks interesting. Also I think that the 4th idea is doable, I have an idea for that, but for now I will just try to get this done :lol:
onekk wrote: Sat May 01, 2021 9:14 am Not a problem, ping me if you want some other suggestions.

I model mostly with Scripting, so I have learn some "intricated ways" to do things, if they are no too intricated and could be useful to someone other than me, i will be very happy to contribute.

Regards

Carlo D.
Thank you very much for your help Carlo, I am new at scripting FreeCAD so I really appreciate it :) I have a question actually.

I manage to make the stair edges which are normal to the path, and now it works with polylines, arcs and splines. So the main problem is almost solved. One isue that popped up now is that how the length of an arc and a line are calculated using the First and the Last parameter. The code I added bellow works for all cases except for one, when there is a combination of lines and arcs in the same wire. The problem is that they are calculated differently, so if I get a line length 1000mm for the length of the arc I will get 2.00 of something(I do not know really what). If the problem is not clear, I can try to explain it better.

5.png
5.png (188.61 KiB) Viewed 1008 times
6.png
6.png (186.55 KiB) Viewed 1008 times

Arcs and straight lines do not work together in this image for example.

Code: Select all

import Part, math
from FreeCAD import Base

width = 200
height = 200
length = 800
num = 80
step_height = height / num
step_width = 30
current_num = []

#path = Part.Arc(Base.Vector(0, 0, 0), Base.Vector(0, 800, 0), Base.Vector(800, 800, 0))
#path_edge = path.toShape()
#Part.show (path_edge)

print ("Select a wire that will form the stairs path:")
s = FreeCADGui.Selection.getSelection()
try:
    path_wire=s[0].Shape
except:
    print ("Wrong selection")

points = []

edges = []
edges_lengths = []
old_length = 0
edges_total = 0
edge_num = 0
edge_num1 = 0

for i in path_wire.Edges:
    edges.append(i)
    print(i.LastParameter - i.FirstParameter)
    edge_length = i.LastParameter - i.FirstParameter + old_length
    edges_lengths.append(edge_length)
    edges_total += edge_length
    old_length = edge_length
    print(old_length)

print(edges_lengths)

pos = 0
pos1 = 0
scale = 1.0 / num * edges_total

for i in range (0, num):
	pos = scale * i
	pos1 = scale * (i + 1)

	if pos >= edges_lengths[edge_num]:
		edge_num += 1
	if pos1 >= edges_lengths[edge_num1]:
		edge_num1 += 1

	if edge_num > 0:
		pos = pos - edges_lengths[edge_num - 1]
	if edge_num1 > 0:
		pos1 = pos1 - edges_lengths[edge_num1 - 1]

	print(edges_lengths[edge_num])
	print(pos)
	print(pos1)

	point_pos = (edges[edge_num].valueAt(pos))
	point_pos1 = (edges[edge_num1].valueAt(pos1))

	angle = (edges[edge_num].tangentAt(pos))
	angle = [angle[1], angle[0] * -1, angle[2]]

	angle1 = (edges[edge_num1].tangentAt(pos1))
	angle1 = [angle1[1], angle1[0] * -1, angle1[2]]

	point = Base.Vector(0, 0, 0)
	point1 = Base.Vector(angle[0]*width, angle[1]*width, 0)
	point2 = Base.Vector(angle1[0]*width, angle1[1]*width, 0)

	edge = Part.makeLine(point, point1)
	edge1 = Part.makeLine(point, point2)

	edge.translate(Base.Vector(point_pos[0], point_pos[1], step_height*i))
	edge1.translate(Base.Vector(point_pos1[0], point_pos1[1], step_height * i))

	Part.show (edge)
	Part.show (edge1)
paullee
Veteran
Posts: 5120
Joined: Wed May 04, 2016 3:58 pm

Re: How would I make a simple path array script?

Post by paullee »

Maybe you would like to edit the 1st post to include Stairs to attract more discussion?

And cross-post in Arch/BIM forum?
ABeton wrote: Sat May 01, 2021 9:17 pm I saw the profile out of stairs idea, it looks interesting.
Some thoughts about a more systematic structure of future codes below :-

Common Stairs (Custom Landing)
  1. For common straight (or circular/spiral) flight, user draw single straight line (or arc) to represent the Run and Arch Stairs do all the jobs
  2. If landing is slightly more complicated, user draw some lines / wire to represent it and Arch Stairs do it
  3. Some of the above ideas was what I started to learn python (still learning) and implemented part of it :)
Consistent Steps (Tread/Riser) + Custom 'Steps Plan Profile'
  1. The most tedious jobs are to generate the repetitive steps/risers profile
  2. So if the Tread/Riser width are consistent, but the 'Steps Plan Profile' is not simple straight path
    (Spanish Steps? Or the example I did in the other thread...)
  3. User provide a straight lines to represent the Run
  4. Just let Arch Stairs to generate the sectional profile, and user create the 'steps plan profile' and Extrude along
  5. Maybe Arch Stairs can accept Simple 'Steps Plan Path' and automate the extrusion also ?
Consistent Steps (Tread/Riser) + Custom Run Profiles
(Other than straight edges / circular/spiral)
  1. So user provide a Wire of combination of straight /curve edges to represent the Run
  2. Arch Stairs to generate the Steps perpendicular to it and offset with a Width defined by user
  3. If user provides 2 Wires, it defines both sides of the Stairs Run
  4. User to choose which sides the Tread should extend perpendicular from (of equal spacing?)
  5. This seems achievable in future ?
Consistent Riser + Custom Tread (Step Plan Shape) + Custom 'Run Profiles'
  1. It seems it is what you are attacking :)
  2. User provide a series of lines represent the Tread, the Riser is still consistent, so you can automate by Ruling Surface etc.
  3. Both sides of the Run Profiles are used to define profiles of both sides of the Stairs (cut / extrude)
Balustrade Profiles
  1. The idea of Steps(Tread/Riser) Profile Generator apply for Balustrade as Well
  2. Except simple single railing, every Balustrade is different
  3. So just generate a profiles follow along the Steps, and let user to use it to e.g. Array Path?
There are other features (capabilities) not included in discussion or it would be far too complicated :D
User avatar
onekk
Veteran
Posts: 6208
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: How would I make a simple path array script?

Post by onekk »

I see the problem, I could think of dividing the wires and act differently for each segment, if it is straight, act in a way, if it is curve, (there will be a mathematical way of calculation if a segment is collinear or not) use the "lengths" and parameters, to obtain the correct angled step.

It may be possible to select simply in base of the segment is collinear or not.

Let me study on it some more, but not today, perhaps, in two or three days. I've other thing to do.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
ABeton
Posts: 150
Joined: Tue Sep 03, 2019 6:39 pm

Re: How would I make a simple path array script?

Post by ABeton »

paullee wrote: Sun May 02, 2021 12:35 am Maybe you would like to edit the 1st post to include Stairs to attract more discussion?

And cross-post in Arch/BIM forum?
ABeton wrote: Sat May 01, 2021 9:17 pm I saw the profile out of stairs idea, it looks interesting.
Some thoughts about a more systematic structure of future codes below :-

Common Stairs (Custom Landing)
  1. For common straight (or circular/spiral) flight, user draw single straight line (or arc) to represent the Run and Arch Stairs do all the jobs
  2. If landing is slightly more complicated, user draw some lines / wire to represent it and Arch Stairs do it
  3. Some of the above ideas was what I started to learn python (still learning) and implemented part of it :)
Consistent Steps (Tread/Riser) + Custom 'Steps Plan Profile'
  1. The most tedious jobs are to generate the repetitive steps/risers profile
  2. So if the Tread/Riser width are consistent, but the 'Steps Plan Profile' is not simple straight path
    (Spanish Steps? Or the example I did in the other thread...)
  3. User provide a straight lines to represent the Run
  4. Just let Arch Stairs to generate the sectional profile, and user create the 'steps plan profile' and Extrude along
  5. Maybe Arch Stairs can accept Simple 'Steps Plan Path' and automate the extrusion also ?
Consistent Steps (Tread/Riser) + Custom Run Profiles
(Other than straight edges / circular/spiral)
  1. So user provide a Wire of combination of straight /curve edges to represent the Run
  2. Arch Stairs to generate the Steps perpendicular to it and offset with a Width defined by user
  3. If user provides 2 Wires, it defines both sides of the Stairs Run
  4. User to choose which sides the Tread should extend perpendicular from (of equal spacing?)
  5. This seems achievable in future ?
Consistent Riser + Custom Tread (Step Plan Shape) + Custom 'Run Profiles'
  1. It seems it is what you are attacking :)
  2. User provide a series of lines represent the Tread, the Riser is still consistent, so you can automate by Ruling Surface etc.
  3. Both sides of the Run Profiles are used to define profiles of both sides of the Stairs (cut / extrude)
Balustrade Profiles
  1. The idea of Steps(Tread/Riser) Profile Generator apply for Balustrade as Well
  2. Except simple single railing, every Balustrade is different
  3. So just generate a profiles follow along the Steps, and let user to use it to e.g. Array Path?
There are other features (capabilities) not included in discussion or it would be far too complicated :D
I changed the name, just not sure how to cross-post? I just make a new post in Arch/BIM subforum?

I agree with most what you said, I just did not understand well what is the difference between the 3rd and 4th type of stairs. Also for Balustrade we could pick any custom model and distribute it make a balustrade I think, we just need the correct points.
onekk wrote: Sun May 02, 2021 10:13 am I see the problem, I could think of dividing the wires and act differently for each segment, if it is straight, act in a way, if it is curve, (there will be a mathematical way of calculation if a segment is collinear or not) use the "lengths" and parameters, to obtain the correct angled step.

It may be possible to select simply in base of the segment is collinear or not.

Let me study on it some more, but not today, perhaps, in two or three days. I've other thing to do.

Regards

Carlo D.
I think I saw a command somewhere to check if an edge is straight or not. Also maybe there is a different method to get the correct length of an arc. And of course, when you have time, I could use some advice :)
User avatar
onekk
Veteran
Posts: 6208
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Custom Path Stairs

Post by onekk »

in "/Mod/Draft/draftgeoutils/geometry.py" there is is_straight_line method but is an old code, and I don't know if it is working to do some test on segments, it use the edge object, so it could be inserted in a loop over the Edges list of a Shape. Maybe.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
paullee
Veteran
Posts: 5120
Joined: Wed May 04, 2016 3:58 pm

Re: Custom Path Stairs

Post by paullee »

ABeton wrote: Sun May 02, 2021 2:57 pm I changed the name, just not sure how to cross-post? I just make a new post in Arch/BIM subforum?

I agree with most what you said, I just did not understand well what is the difference between the 3rd and 4th type of stairs. Also for Balustrade we could pick any custom model and distribute it make a balustrade I think, we just need the correct points.
Maybe just create a new post and put a link of this thread.

And some images to illustrate the 2nd to 3rd types below :) 4th type is what you are doing :D

In fact, I just add 2 solid and subtract from a standard Stairs to do the 3rd mock-up...


2nd Type
Screenshot from 2019-05-22 00-29-04.png
Screenshot from 2019-05-22 00-29-04.png (231.37 KiB) Viewed 912 times


3rd Type
Screenshot from 2021-05-03 00-30-32.png
Screenshot from 2021-05-03 00-30-32.png (208.72 KiB) Viewed 912 times
Post Reply