Problem copying TitleBlockDefinition

Problem copying TitleBlockDefinition

a.brusamolino
Enthusiast Enthusiast
178 Views
2 Replies
Message 1 of 3

Problem copying TitleBlockDefinition

a.brusamolino
Enthusiast
Enthusiast

Hi!
I have a working code, but I’d like to make a change because I don’t like how it functions.
Basically, what I want to do is: open the IDW template, get the TitleBlockDefinition of a specific title block, and copy it into another file.
So far, so good.

 

The problem is that the variable I create to obtain the TitleBlockDefinition remains "active" as long as the template stays open (and I don’t understand why... once I’ve retrieved the content, shouldn’t I be done with it and be detached from the source file?). If I close the source file, the variable loses this information, and I can no longer copy the TitleBlockDefinition into other files.

Since I have several files to loop through, I’d like to avoid keeping the template open for too long.

 

I’m attaching simplified versions of the code to clarify the issue. The first one works, while the second one (which I’d like to implement) doesn’t. 

Can you help me understand why?

Thank you very much.

 

 

' WORKING

Dim oTempDrawing As DrawingDocument = ThisApplication.Documents.Open("myTemplatePath", False)
Dim oTitleBlockDef As TitleBlockDefinition = oTempDrawing.TitleBlockDefinitions.Item("MyTitleBlockName")

For Each idwfile [..]
     ' Doing My things
     ' Copying TitleBlockDefinition
Next

oTempDrawing.Close 
' NOT WORKING

Dim oTempDrawing As DrawingDocument = ThisApplication.Documents.Open("MyTemplatePath", False)
Dim oTitleBlockDef As TitleBlockDefinition = oTempDrawing.TitleBlockDefinitions.Item("MyTitleBlockName")
oTempDrawing.Close

For Each idwfile [..]
     ' Doing My things
     ' Copying TitleBlockDefinition
Next

 

 

0 Likes
Accepted solutions (1)
179 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Hi @a.brusamolino.  I think this is just a general behavior of how 'normal' variables work in vb.net, depending on the 'Type' of data it is representing.  There are 'data types' and there are 'referenced objects'.  Data types are sort of like Double, Integer, Boolean, String, while reference objects are like a Document, Sheet, PartsList, TitleBlock, and such.  The variables holding onto data type values, are not 'referencing' any external source, just direct, simple data.  But the variables holding onto a reference object are essentially 'pointing to' that object that is being referenced from its source.  So, if that reference object has not been copied anywhere else yet, and the 'source' of that referenced object becomes unavailable, the variable can no longer point to it.

 

What you may benefit from here is using a uniquely iLogic 'SharedVariable'.  There are some 'standard snippets' for these in the iLogic rule editor, so you can read more about them at the following online help page.

Variables Functions Reference (iLogic) 

However, in case that system has the same limitation, you may simply have to copy the definition locally, such as into the 'active' drawing document first, making sure your variable is then pointing to that local copy of that data, then close the template, then proceed with the rest of your code.  But I really don't see much downside to leaving that template open until you are done copying the definition to other drawing files.  Having that one document open in the background should not make that much difference in performance.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

a.brusamolino
Enthusiast
Enthusiast

@WCrihfield thanks for the clarification. That makes sense.

 

Yes, exactly. It’s not a big deal to keep the template open—it was more of a personal preference/pet peeve. I just don’t like the idea of having it open while performing other operations.

At this point, I think I’ll do as you suggested in the end: I’ll open a new file so I can point directly to it without involving the template.

 

Thanks again!

0 Likes