Import Sketched Symbols

Import Sketched Symbols

darrell.wcd
Enthusiast Enthusiast
1,608 Views
14 Replies
Message 1 of 15

Import Sketched Symbols

darrell.wcd
Enthusiast
Enthusiast

I found some code and edited it to suit my needs, and it has worked flawless for several years, and now as of last week it has stopped working. And I don't understand the error message. Also it works on a different machine, but am I missing something in the code to make it work with any configuration or machine?

 

It copies the sketch symbols from my template to current drawing resources, and overwrites with any new. Very nice update tool.

 

Error Message:

Error in rule: SU_SketchSymbols, in document: TTA-001214.dwg

Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))

 

More Info:

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.SketchedSymbolDefinition.CopyTo(_DrawingDocument TargetDocument, Boolean ReplaceExisting)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

Sub Main()

    Dim oApp As Inventor.Application
    oApp = ThisApplication
    Dim thisDWG As DrawingDocument
    thisDWG = oApp.ActiveDocument
    
    'Define source path of Symbol Drawing
    Dim pathDWG As String
    pathDWG = "C:\$WorkingFolder\Templates\TitleBlockEditor.dwg"
    
	
	
    Dim sourceDWG As DrawingDocument
	
    sourceDWG = oApp.Documents.Open(pathDWG, False)
    
    Dim symbolDef As SketchedSymbolDefinition
    
    'Copy all the symbols into active drawing
    For Each symbolDef In sourceDWG.SketchedSymbolDefinitions
        Call symbolDef.CopyTo(thisDWG, ReplaceExisting :=False)
		
    Next
	
'colapse browser	
	Dim oTopNode As BrowserNode
oTopNode = thisDWG.BrowserPanes.ActivePane.TopNode
Dim oNode As BrowserNode

For Each oNode In oTopNode.BrowserNodes
' If the node is visible and expanded, collapse it.
If oNode.Visible = True And oNode.Expanded = True Then
oNode.Expanded = False
End If
Next


End Sub 

 

0 Likes
Accepted solutions (1)
1,609 Views
14 Replies
Replies (14)
Message 2 of 15

bradeneuropeArthur
Mentor
Mentor

is the path still correct?!

 

pathDWG = "C:\$WorkingFolder\Templates\TitleBlockEditor.dwg"

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 15

darrell.wcd
Enthusiast
Enthusiast

Yes it is, it works fine on another machine with the same local vault working folder location C:\$WorkingFolder\...

 

0 Likes
Message 4 of 15

MjDeck
Autodesk
Autodesk

Can you post the drawing file TitleBlockEditor.dwg?
Does it fail in all drawings on your machine?


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 5 of 15

darrell.wcd
Enthusiast
Enthusiast

Here is a copy of the template.

Yes it fails on all drawings on my machine, and works fine on my laptop.

0 Likes
Message 6 of 15

bradeneuropeArthur
Mentor
Mentor

What version of inventor are you working with.

the template is at least 2019 version or later.

this cannot be opened in earlier versions.

 

this seems to be the problem I think.

did you or colleague open it in a newer version of inventor?

 

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 7 of 15

darrell.wcd
Enthusiast
Enthusiast

no this is not the problem, all machines are running IV 2019

0 Likes
Message 8 of 15

bradeneuropeArthur
Mentor
Mentor

did you test to open the template file manually on the machine that is not working?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 9 of 15

darrell.wcd
Enthusiast
Enthusiast

I guess there are users that would post these questions without trying to figure it out themselves.

I've been running inventor for 8 years +-

 

Yes it opens fine. No problems there at all.

0 Likes
Message 10 of 15

bradeneuropeArthur
Mentor
Mentor

Hi,

 

Than you have 8 year + experience!

With this in mind you should have a look at the code basics.

One of the rules with programming is to clarify all parameters and objects correctly.

 

Seems that there is a lot of declaration missing in your code.

	
For Each oNode In oTopNode.BrowserNodes
' If the node is visible and expanded, collapse it.
If oNode.Visible = True And oNode.Expanded = True Then
oNode.Expanded = False
End If
Next

So first take a look at this.

 

Regards,

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 11 of 15

matt_jlt
Collaborator
Collaborator

Here is a working / tested solution. I added a file exist check and a try catch so if the file doesn't exist it will tell you. Also, it never closed the sketch symbol template file so i added that and simplified it a bit and you said you wanted it to replace the symbols if they were there so i changed the option from False to True to fix that.

 

Also, the oNode and Top node were declared correctly, it was the three lines directly above.

 

Dim oTopNode As BrowserNode
oTopNode = thisDWG.BrowserPanes.ActivePane.TopNode
Dim oNode As BrowserNode

 

Completed code here:

Try 
	' Check active document type is a drawing document
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
		
	' Get active document
	Dim oCurDoc As DrawingDocument = ThisApplication.ActiveDocument

	' Sketch symbol document
	Dim strPath As String = "C:\$WorkingFolder\Templates\TitleBlockEditor.dwg"
	
	' Check file exists
	If System.IO.File.Exists(strPath) = False Then : messagebox.Show("File doesn't exist","Update IDW Symbols") : Exit Sub : End If
	
	' Open file
	Dim oOldDoc As DrawingDocument = ThisApplication.Documents.Open(strPath, False)

	' Iterate through each symbol in the old document
	For Each oSD As SketchedSymbolDefinition In oOldDoc.SketchedSymbolDefinitions
		' Copy sketched symbols to new document and replace if existing
		oSD.CopyTo(oCurDoc, True)
	Next

	' Close old document without save
	oOldDoc.Close(True)

	' Iterate through drawing resources browser nodes and collapse expanded ones 
	Dim oTopNode As BrowserNode = oCurDoc.BrowserPanes.ActivePane.TopNode ' Top node is drawing resources folder
	For Each oNode As BrowserNode In oTopNode.BrowserNodes
		If oNode.Visible = True And oNode.Expanded = True Then oNode.Expanded = False
	Next

	' Prompt for completion
	messagebox.Show("Symbol Updated Complete", "Update IDW Symbols")
	
Catch Ex As Exception
	Messagebox.Show(Ex.Message, "Update IDW Symbols")
End Try

 

0 Likes
Message 12 of 15

darrell.wcd
Enthusiast
Enthusiast

There seams to still be something not working.

I added a message box check point, before Line 23, and go the message for each symbol, and then got the error msg.

Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))

 

It worked once on another machine, now I get the same error.

And the original does not work on the other machine now either.

 

Things are really going down hill.

0 Likes
Message 13 of 15

JamieVJohnson2
Collaborator
Collaborator

Everything posted here works fine, but one thing has not been posted here.  Your new file.  The old file may be ok, the code may be ok, but we need to see a copy of the new file to determine if it is the cause of your problem.  I ran the code in visual studio (with a little change for ThisApplication), and the code worked without any errors, on my company template file (in 2020 inventor btw) without any file conversions necessary (from your 2019 Inventor .dwg file).  I would like to see a copy of your 'new' file to see if I can reproduce your error and perhaps discover something.  However bear in mind I'm testing in 2020, so if it is an Inventor bug, it may have already been fixed.

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
Message 14 of 15

MjDeck
Autodesk
Autodesk
Accepted solution

I tested in 2019.4.
I get the "Unspecified error" message if the destination drawing is saved in a Library folder. @darrell.wcd , can you confirm that you get the error message on either of these:

  • a new drawing that has not been saved
  • a drawing that has been saved to the Workspace path of the active project

If you're not working in a Library folder:
On a drawing that throws the error, can you copy the sketch symbols manually, without using the rule? That is, can you open the source document, copy the sketch symbols, and paste them into the destination document? Does that work with no error?


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 15 of 15

darrell.wcd
Enthusiast
Enthusiast

okay @MjDeck  I did some digging on this.. I found that someone had opened the file, saved as a idw and then back to a dwg to remove some gost links or something they thought were causing some problems. I reverted back to the version before that and now it works fine. both the old code and the new code. I will be using the new code with the correct error handling. thanks @bradeneuropeArthur  and @matt_jlt  for your help with the updated code.

0 Likes