- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to write some code that will automatically project geometry from a component occurrence inserted into an assembly drawing. The program loops through all of the components in the assembly and looks for a sketch named "sk_Cutout". If it finds that sketch, it then needs to project the geometry from the component sketch ("sk_Cutout") to the assembly sketch named "sketchDoor". (A screenshot of a "sk_Cutout" sketch is attached).
The follow code is my start on this project. Everything works well except for the most important part (and that is projecting the geometry). I have noted in the code below where the program crashes.
Any ideas?
Public Sub extrudeSketch()
'this checks to make sure Inventor is open and
'sets oAssemblyDocument to the active inventor document
CheckInventor()
'set some variables
Dim oDef As AssemblyComponentDefinition
oDef = oAssemblyDocument.ComponentDefinition
Dim oPartDef As ComponentDefinition
Dim oOcc As ComponentOccurrence
Dim oOccs As ComponentOccurrences = oDef.Occurrences
Dim sk As Sketch = Nothing
Dim skEnt As SketchEntity = Nothing
Dim skEntNew As SketchLine = Nothing
Dim oSketchLine As SketchLine = Nothing
'sketch door is where the new sketch geometry will be placed
Dim sketchDoor As PlanarSketch = oAssemblyDocument.ComponentDefinition.Sketches.Item("sketchDoor")
'loop through all of the components in the assembly
For Each oOcc In oOccs
oPartDef = oOcc.Definition
'loop through all of the sketches in the component
'search for sketch name "sk_Cutout"
For Each sk In oPartDef.Sketches
If sk.Name = "sk_Cutout" Then
'we have found the sketch we are looking for
sketchDoor.Edit()
For Each skEnt In sk.SketchEntities
If skEnt.Type = ObjectTypeEnum.kSketchLineObject Then
oSketchLine = skEnt
Debug.Print(oSketchLine.Length.ToString)
Debug.Print(skEnt.Type.ToString)
'/////////// here is where the program crashes ///////////////////
skEntNew = sketchDoor.AddByProjectingEntity(oSketchLine)
End If
Next
'exit the sketch
sketchDoor.ExitEdit()
End If
Next
Next
End Sub
Solved! Go to Solution.