I have just started using Dynamo and learning Python. I would like to import “Feature Lines” from Civil 3D into Dynamo but I don’t think there is a node for that. Having said that, I think the best way forward is to import using Python. I have written a code based on a video I have watched online. The code is as shown:
@Clive_Owen, please have a look at this example I’ve put together, it takes the Land Feature Lines from Sites and not and converts them into PolyCurves. GetLandFeatureLines.dyn (5.8 KB)
def get_featurelines():
“”"
Extract the Land Feature Lines in the document and converts them into Dynamo PolyCurves
:returns: Dynamo PolyCurves
“”"
global adoc
global cdoc
output = []
with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
bt = t.GetObject(db.BlockTableId, OpenMode.ForWrite)
btr = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
fls = []
for oid in btr:
fl = t.GetObject(oid, OpenMode.ForRead)
if isinstance(fl, FeatureLine) and fl.SiteId == ObjectId.Null:
pts = []
for pt in fl.GetPoints(FeatureLinePointType.AllPoints):
pts.append(DS.Point.ByCoordinates(pt.X, pt.Y, pt.Z))
if len(pts) > 1:
fls.append(DS.PolyCurve.ByPoints(pts))
if len(fls) > 0:
output.append(fls)
for sid in cdoc.GetSiteIds():
site = t.GetObject(sid, OpenMode.ForRead)
fls = []
for fid in site.GetFeatureLineIds():
fl = t.GetObject(fid, OpenMode.ForRead)
pts = []
for pt in fl.GetPoints(FeatureLinePointType.AllPoints):
pts.append(DS.Point.ByCoordinates(pt.X, pt.Y, pt.Z))
if len(pts) > 1:
fls.append(DS.PolyCurve.ByPoints(pts))
if len(fls) > 0:
output.append(fls)
return output
Hi Paolo! Thanks for the response! I have tried creating a Feature Line and assigning it to a site. However, I am still unable to extract out the FL into Dynamo. I am not sure if I am doing anything wrong.
Hi Paolo! I have figured out the problem. For some reasons, I have to make changes to the python script (e.g. insert/delete an empty line) and save the changes each time I want to run the script. Not sure if it’s a bug or something else. Thank you!
@arthursmmun, no bugs here
This is how Dynamo works, if a node, any node, has no updated input it will not take part to the execution next time you run the graph.
If you think about it is a smart move: it calculates only the portion of the graph that actually needs to be updated, you just need to know the rules of the game
In this case you could have simply pressed on the plus/minus buttons on the Python Script node to change its state and force it to recalculate the results.
Please try the following, set the run mode to Automatic, assume you have no Feature Lines in the document, the Python node will return, correctly, Empty List.
In Civil 3D you add a Feature Line with no Site assigned, nothing changes in Dynamo, you click on the plus sign, the node now returns one Feature Line under the List of unassigned Feature Lines.
Then in Civil 3D you create a Feature Line to a Site, nothing changes in Dynamo, you click on the minus sign, now the code returns two Feature Lines under a different grouping.
You can of course also edit the script as you said but you don’t need to save the changes you can just run it from the Python editor.
The method you are using is necessary only when you are making changes to an external module and you want to force Python to reload it.
Is it possible to only have the Feature Lines as output from the node, so I can alter the elevations of the points in another (python) node?
Or do I have to alter the elevations of the points in one single Python node?
What I would like to do is to alter several FLs their elevation points with elevations extracted from a TIN surface.
With your Python node I can create Polyline3D objects from FLs with elevations extracted from a TIN surface already. But I would like to do this with FLs only, without doing a ‘conversion’ to Polylines and without doing this in one single Node. Or should I…?
@lapis you can do it via the same Python script node, what it currently does is merely selecting the right objects in the document. I’m not sure how you want to edit the elevations though, that is the key for the automation you are asking. A tip, think how do you specify the inputs, how do you want to process them and hot the output should look like when it is correct. Put it on paper, use Dynamo nodes if you need to show a workflow diagram and then you can find the logic in Python to do what you have in mind.
Hi @Paolo_Emilio_Serra1, I tried the script on a Land Feature Line containing curves but Dynamo is not converting them correct. I only get the original vertex points without the curves. Any solution to this yet?
This works well, but I’m looking for help modifying the python script so it only brings in a selection set of feature lines. I don’t want every feature line in the drawing. For instance, I am using the ObjectByProperty node to select feature lines with a specific property set property. I only want to bring these features lines into Dynamo.