Struggling with Alignment.CopyToSite() method with .NET on Python

Struggling with Alignment.CopyToSite() method with .NET on Python

Anonymous
Not applicable
1,712 Views
4 Replies
Message 1 of 5

Struggling with Alignment.CopyToSite() method with .NET on Python

Anonymous
Not applicable

Hello and thank you for the attention.

 

I am using Dynamo for Civil 3D's Python Script. There I started working on some rutines successfully. Now, trying to copy an alignment I found that CopyToSite() method does not work properly. I mean, apparently it doesn't follow any rules. Sometimes it works and when it works is weird because mostly those times I enter CopyToSite("SampleSite") and it generates a siteless alignment.

 

I am very confused and curious. ¿Could anyone help me?      .dwg and .dyn attached

Many thanks

 

I tried with all parameters possible (''), ('string'), (None) or (ObjectId)

Using Civil 3D 2020

0 Likes
Accepted solutions (1)
1,713 Views
4 Replies
Replies (4)
Message 2 of 5

Jeff_M
Consultant
Consultant
This is all new to me so it took a bit to figure out how to even use the script. Now that I've got that worked out, I'm seeing that CopyToSite will only work with SitelessAlignments. Trying to copy a siteless alignment to a Site results in a new Siteless alignment. Trying to copy an alignment in a Site results in no new alignment.

Strange thing is that the CopyToSite works fine when used in a typical .NET assembly (created in VS c#). Why it's failing to work in Python, I have no idea.
Jeff_M, also a frequent Swamper
EESignature
Message 3 of 5

tyronebk
Collaborator
Collaborator
Accepted solution

For testing, I simplified the code to:

sitename = IN[0]
doc = acapp.DocumentManager.MdiActiveDocument
with doc.LockDocument():
	with doc.Database.TransactionManager.StartTransaction() as t:
		for id in CivilApplication.ActiveDocument.GetAlignmentIds():
			al = t.GetObject(id, OpenMode.ForRead)
			al.CopyToSite(sitename)
		t.Commit()
OUT = True

Run this code and the alignments are all copied to the named site ... eventually. There is some sort of lazy execution happening here.

 

The alignments are immediately copied as siteless alignments and appear in the Alignments > Centerline Alignments node. Then, after some time, they are moved to the Site node. This might simply be a toolspace refresh delay issue.

 

I was able to make this above code act more predictably by appending a REGEN execution after the commit (but this might just be some sort of confirmation bias in my testing).

import System
# ...
app = System.Runtime.InteropServices.Marshal.GetActiveObject("Autocad.Application")
AcDoc = app.ActiveDocument
AcDoc.SendCommand('REGEN ')

I was only able to get your code to work if a site name was specified and the REGEN command was sent after the  TramoCorridor method executed.

Message 4 of 5

Anonymous
Not applicable

Thanks a lot for the attention and time spent. Hope that getting into Dynamo's Python was at least, a new expirience so we both learn 😀. Thanks

0 Likes
Message 5 of 5

Anonymous
Not applicable

YEAH, that's right! Thank you very much. That solution ('REGEN') is working well.  You defined the problem and solution with accuracy.

 

Thanks for the time spent

0 Likes