Inventor 2016 Calling Insert Sketch Symbol Crashes Everytime

Inventor 2016 Calling Insert Sketch Symbol Crashes Everytime

matt_jlt
Collaborator Collaborator
554 Views
5 Replies
Message 1 of 6

Inventor 2016 Calling Insert Sketch Symbol Crashes Everytime

matt_jlt
Collaborator
Collaborator

I'm having a problem with executing the command to insert sketch symbols in Inventor 2016, please note that this code is working perfectly in Inventor 2017. It seems as though the pre-selection of the sketch symbol isn't working. Normally when it's run, the preview of the sketch symbol you are inserting is shown and when you click to place it, it adds it to the sheet. With Inventor 2016, the preview is not shown, just the little cursor icon to show where you are placing the symbol, and as soon as you click to place it, Inventor crashes.

 

' Get sketch symbol definition reference
Dim oSketchSymbolDef As SketchSymbolDefinition = ThisApplication.ActiveDocument.SketchedSymbolDefinitions.Item(1)

' Clear select set + add sketch symbol def
oDoc.SelectSet.Clear()
oDoc.SelectSet.Select(oSketchSymbolDef)


 ' Insert sketch symbol
ThisApplication.CommandManager.ControlDefinitions("DrawingUserDefinedSymbolsQuickCtxCmd").Execute()

Any help is appreciated, thanks, Matt.

0 Likes
555 Views
5 Replies
Replies (5)
Message 2 of 6

frederic.vandenplas
Collaborator
Collaborator

Hi,

 

Dim oSketchSymbolDef As SketchSymbolDefinition should be
Dim oSketchSymbolDef As SketchEDSymbolDefinition
If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes
Message 3 of 6

matt_jlt
Collaborator
Collaborator

That was just a typo, the code i am running is correct SketchedSymbolDefinition.

0 Likes
Message 4 of 6

frederic.vandenplas
Collaborator
Collaborator

Ok, i've tested the code and everything worked fine here, do you still have an error?

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes
Message 5 of 6

matt_jlt
Collaborator
Collaborator
Thanks for testing 🙂 it's weird because I've been able to repeat the crash on three machines in vba and .net. I might have to check again that's I haven't done anything like a spelling mistake somewhere else to cause it.

Can I ask if you are running it in inventor 2016 or 2017 and as an illogic rule or vba...

Thanks again,Matt.
0 Likes
Message 6 of 6

matt_jlt
Collaborator
Collaborator

I am having the same issues with Inventor 2018 Pro. Can someone please help with the issue? I have some code that I used to regularly use to place my sketch symbols which I can no longer use.

 

If anyone has a fix or alternate method to place sketch symbols with vba / vb.net code it would be much appreciated if you could help me.

 

I can repeat this error using VB.Net + VBA.

 

I found another reference where @Anonymous mentions this code as a working solution in 2007 but it no longer works.

https://forums.autodesk.com/t5/inventor-customization/sketched-symbols-still/m-p/2078583/highlight/true#M22430

 

below is the full code again in VBA that causes the error.

 

Sub sketchsymbolcrash()

    Dim oDoc As DrawingDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    ' Define sketch symbol definition
    Dim oSSD As SketchedSymbolDefinition
    Set oSSD = oDoc.SketchedSymbolDefinitions.Item(1) ' Any sketch symbol will work for this example
    
    ' Clear select set and select the chosen sketch symbol definition
    Call oDoc.SelectSet.Clear
    Call oDoc.SelectSet.Select(oSSD)
    
    ' Check something was selected
    If oDoc.SelectSet.Count = 0 Then
        MsgBox "Sketch symbol was not selected", "error"
        Exit Sub
    End If
    
    ' Insert sketch symbol
    Call ThisApplication.CommandManager.ControlDefinitions("DrawingUserDefinedSymbolsQuickCtxCmd").Execute
End Sub

thanks, Matt.

0 Likes