So, working in the Draft Workbench, but using the Gui to pick points/objects.
As an exercise, we put a Draft.Arc and Draft.Point on the XY-Plane (top view).
- Screen Shot 2022-07-25 at 2.12.49 PM.png (8.39 KiB) Viewed 485 times
as in enclosed joinpointtoarc.FCStd
Let's write some code that allows us to first multiselect the point and the arc then the Macro makes 5 equidistant lines from the point to the arc like this.
- Screen Shot 2022-07-25 at 2.16.27 PM.png (10.46 KiB) Viewed 485 times
Here's the code:
First we grab the two selections.
Gui.Selection.getSelectionEx() is often the one you want.
Gui.Selection.getSelection() just gets the entire Document Object, without information about the particular SubObject (Edge, Vertex, Face) you selected.
Code: Select all
#multiselect the point then the arc
pointsel, arcsel = Gui.Selection.getSelectionEx()
Now we get the location of the point. We just did this.
Code: Select all
pointloc = point.Object.Shape.Point
print(pointloc)
Our second selection was the arc, we dig into its topology then geometry
arcsel.Object is the Document object (Arc). Its topology is inside
arcsel.Object.Shape
We get the locations of its end-point vertexes
Code: Select all
arcedge = arcsel.Object.Shape
print(arcedge) # it's an edge object - topology
v0, v1 = arcedge.Vertexes
print(v1.Point, v2.Point)
To find out the geometry, we need to go down from the topology level (vertex, edge, face, solid etc.) to the geometry (line, arc, BSpline etc.) level. For an edge it is
Curve, for a face it's
Surface.
Code: Select all
#now what geometry is Edge?
arc.edge.Curve # Circle (Radius : 27.1395, Position : (-34.7107, 9.03188, 0), Direction : (0, 0, 1))
#note that this is an entire circle - but we want the arc
print(arcedge.Curve.trim(*arcedge.ParameterRange)) #
#ArcOfCircle (Radius : 27.1395, Position : (-34.7107, 9.03188, 0), Direction : (0, 0, 1), Parameter : (6.26342, 6.82674))
arcedgecurve = arcedge.Curve.trim(*arcedge.ParameterRange)
print(arcedgecurve.Center) #Vector (-34.71074295043945, 9.031879425048828, 0.0)
There's some tricky stuff there, that took me a while to get figured out. LineSegments are trimmed infinite Lines, ArcOfCircle are trimmed Circles, with a restricted parameter range.
Note that
arcedge.Curve returns the entire Circle, you want just the portion that describes the arc:
arcedge.Curve.trim(* arcedge.ParameterRange)
Now let's draw the desired lines:
Code: Select all
arcpoints = arcedgecurve.discretize(5) #five equally-spaced points along arc
for arcpoint in arcpoints:
Draft.makeLine(pointloc, arcpoint)
The entire script:
Code: Select all
#multiselect the point then the arc
pointsel, arcsel = Gui.Selection.getSelectionEx()
pointloc = point.Object.Shape.Point
print(pointloc)
arcedge = arcsel.Object.Shape
v0, v1 = arcedge.Vertexes
print(v1.Point, v2.Point)
#now what geometry is Edge?
arc.edge.Curve # Circle (Radius : 27.1395, Position : (-34.7107, 9.03188, 0), Direction : (0, 0, 1))
#note that this is an entire circle - but we want the arc
print(arcedge.Curve.trim(*arcedge.ParameterRange)) #
#ArcOfCircle (Radius : 27.1395, Position : (-34.7107, 9.03188, 0), Direction : (0, 0, 1), Parameter : (6.26342, 6.82674))
arcedgecurve = arcedge.Curve.trim(* arcedge.ParameterRange)
print(arcedgecurve.Center) #Vector (-34.71074295043945, 9.031879425048828, 0.0)
arcpoints = arcedgecurve.discretize(5) #five equally-spaced points along arc
for arcpoint in arcpoints:
Draft.makeLine(pointloc, arcpoint)