Replace the existing resource on drawing

ReneRepina
Collaborator

Replace the existing resource on drawing

ReneRepina
Collaborator
Collaborator

Hello.

Is it possible to replace the existing resource on drawing via iLogic?
We have old drawing, that have old sketch symbol styles. They are named the same, so we would just like to run the iLogic rule and replace the same-named sketch symbols with up-to-date styles.

 

ReneRepina_0-1726146331138.png

 

 

Best regards,

Rene Repina

0 Likes
Reply
320 Views
4 Replies
Replies (4)

WCrihfield
Mentor
Mentor

Hi @ReneRepina.  Yes, that is possible.  Below is a link to the method for doing that.

SketchedSymbolDefinition.CopyTo 

The second thing it asks for is 'Optional', and a Boolean, asking if you want to 'Replace' an existing instance of this definition, if one already exists in the 'destination' DrawingDocument.

PS.  Here is a quick example of how to use it:

When you have an old drawing open, run this rule, and it will open your 'template' (or just another) drawing (invisibly), get the specific SketchedSymbolDefinition from it, copy it to your current drawing, and replace existing (if any) in the process, then dispose of the template drawing it opened invisibly, then update the current drawing.

Sub Main
	Dim oDDoc As DrawingDocument = TryCast(ThisDoc.Document, Inventor.DrawingDocument)
	If oDDoc Is Nothing Then Return
	Dim oTDDoc As DrawingDocument = ThisApplication.Documents.Open("C:\Temp\MyDrawingTemplate.idw", False)
	Dim oTSSDef As SketchedSymbolDefinition = oTDDoc.SketchedSymbolDefinitions.Item("MySketchedSymbolDefinition")
	Dim oSSDef As SketchedSymbolDefinition = oTSSDef.CopyTo(oDDoc, True)
	oTDDoc.ReleaseReference()
	oDDoc.Update2(True)
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

ReneRepina
Collaborator
Collaborator

Hello @WCrihfield !

 

Wow, thank you for code example!

I will try it soon when I have the time and will let you know of the result!

 

P. S.:
Instead of "ReleaseReference()" you could simply use "Close(True)" method?

 

 

Best regards,

Rene Repina

0 Likes

WCrihfield
Mentor
Mentor

Hi @ReneRepina.  You can likely use Close method instead if you want to.  I am just not sure it will have the same performance benefits when used in large scale operations, such as batch processing all files in a folder.  When we open a document visibly, then we must use the Close method to close it, instead of just the ReleaseReference method.

 

We should only use the ReleaseReference method on documents that we know are not currently visibly open, and we know they are not currently being referenced by any other open documents, and we have either already saved them, or do not want to save them.  It is primarily beneficial to use when iterating whole folders (or directories) of files at a time, where we are temporarily opening them invisibly, then no longer need them for anything, because it helps performance, when used together with the Documents.CloseAll(True) method, where the Optional True specifies only close all the unreferenced documents.  These are not always a necessity, but more of a bonus tool.

 

When we use the Close method on a visibly open document, if that document is still being referenced by some other open document, then any views of that Document will be closed, but that Document will remain loaded in Inventor's memory.  However, I think that if the Document was already not visible, and is being referenced by some other open document, and you try to use the Close method (or the ReleaseReference method) on it, it may sometimes throw an error, because it can not be closed (or released) any further due to it being referenced.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

ReneRepina
Collaborator
Collaborator

@WCrihfield 

 

Wow! Nice insight, thank you for this, I did not know that!

0 Likes