insert sketch in drawing

insert sketch in drawing

GKR2023
Enthusiast Enthusiast
274 Views
2 Replies
Message 1 of 3

insert sketch in drawing

GKR2023
Enthusiast
Enthusiast

Hello.

 

I am useing this code:

https://forums.autodesk.com/t5/inventor-programming-ilogic/insert-sketch-symbol-using-ilogic/td-p/43...

And adjusted it a bit:

Sub Main()
	
Dim oDoc As Document = ThisDoc.Document
If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("Active document is not a drawing")
	Exit Sub
End If
	
	Dim oDrawDoc As DrawingDocument = ThisDrawing.Document
	Dim oSheet As Sheet = oDrawDoc.ActiveSheet
	Dim oSketchedSymbolDef As SketchedSymbolDefinitions = oDrawDoc.SketchedSymbolDefinitions.Item("Sheet Metal DXF-/STEP-file")
	
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	Dim oInsertionPoint As Point2d = oTG.CreatePoint2d(oSheet.Border.RangeBox.MaxPoint.X, oSheet.Border.RangeBox.Y)
	
	Dim oSketchedSymbol As SketchedSymbol = oSheet.SketchedSymbols.Add(oSketchedSymbolDef,oInsertionPoint, 0.0, 1.0, Nothing)
		
End Sub

But I get the following error on rule 11.

The symbol is there.

GKR2023_0-1699949519653.png

What am I doing wrong?

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

JelteDeJong
Mentor
Mentor
Accepted solution

It looks like your sketched symbol is in a library file. You need to copy it first to your drawing the you can use it. Try this:

Dim doc As Document = ThisDoc.Document
If doc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
    MsgBox("Active document is not a drawing")
    Exit Sub
End If
Dim sheet As Sheet = doc.ActiveSheet

Dim project = ThisApplication.DesignProjectManager.ActiveDesignProject

Dim libraryPath = System.IO.Path.Combine(project.DesignDataPath, "Symbol Library\Library.idw")
Dim libDoc = ThisApplication.Documents.Open(libraryPath, False)

Dim sketchedSymbolDef As SketchedSymbolDefinition = libDoc.SketchedSymbolDefinitions.Item("Sheet Metal DXF-/STEP-file")
sketchedSymbolDef = sketchedSymbolDef.CopyTo(doc, True)

libDoc.Close(True)

Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oInsertionPoint As Point2d = oTG.CreatePoint2d(sheet.Border.RangeBox.MaxPoint.X, sheet.Border.RangeBox.MaxPoint.Y)

sheet.SketchedSymbols.Add(sketchedSymbolDef, oInsertionPoint, 0.0, 1.0, Nothing)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 3

GKR2023
Enthusiast
Enthusiast

This worked! Thank you for the explanation!

Ciao
0 Likes