Message 1 of 1
add new Sketch in DerivedPartComponents
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey,
I need to insert a sketch in a Derived Part.
after selecting a face in an assembly, I query whether the part has a Derived Part.
Afterwards I look for the same face in the Derived Part and save it, which is then passed to a function.
Then I use the face for the add sketch command, but always get the error : HRESULT: 0x80070057 (E_INVALIDARG)
Any Ideas?
Sub:
Private Sub btn_comp_Click(sender As Object, e As EventArgs) Handles btn_comp.Click
Dim oPartFaceSelection
Dim SketchComp As ComponentOccurrenceProxy
Dim funcBool As Boolean
Dim oPartFace1Selection As Edge
If language = "de-DE" Then
oPartFaceSelection = ivExe.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Skizziereben auswählen")
ElseIf language = "fr-FR" Then
oPartFaceSelection = ivExe.CommandManager.Pick(SelectionFilterEnum.kPartBodyFilter, "Sélectionner le plan d'esquisse")
End If
Dim oPartOcc As ComponentOccurrence = oPartFaceSelection.ContainingOccurrence
Dim oPartSelection
If oPartOcc.Definition.ReferenceComponents.DerivedPartComponents.Count >= 1 Then
Me.lbl_comp.Text = oPartOcc.Name & " (" & oPartOcc.Definition.ReferenceComponents.DerivedPartComponents.Item(1).Name & ")"
oPartSelection = oPartOcc.Definition.ReferenceComponents.DerivedPartComponents.Item(1)
Dim pryBody As ReferenceFeature = oPartSelection.PrimaryBody
Dim bodyFaces As Faces = pryBody.Faces
For x = 1 To bodyFaces.Count - 1
Dim face As Face = bodyFaces.Item(x)
If face.InternalName = oPartFaceSelection.InternalName Then
oPartFaceSelection = bodyFaces.Item(x)
End If
Next
funcBool = True
Else
Me.lbl_comp.Text = oPartOcc.Name
oPartSelection = oPartOcc
funcBool = False
End If
Console.WriteLine(TypeName(oPartFaceSelection))
createSketch(oPartFaceSelection, oPartSelection, funcBool)
End Sub
Function: (Error on Line16)
Function createSketch(Sketchface, oPartDoc, bool)
Dim oSketch As PlanarSketch
Dim oExistisSketches
Dim sketchCounter As Integer
sketchName = "Sketch_" & sketchCounter
If bool = True Then 'dervied Parts
oExistisSketches = oPartDoc.Definition.Sketches
For s = 1 To oExistisSketches.Count
If oExistisSketches.Item(s).ReferencedEntity.Name = sketchName Then
sketchCounter += 1
sketchName = "Sketch_" & sketchCounter
End If
Next
If Sketchface.SurfaceType = SurfaceTypeEnum.kPlaneSurface Then
oSketch = oPartDoc.ReferencedDocumentDescriptor.ReferencedDocument.ComponentDefinition.Sketches.Add(Sketchface)
oSketch.Name = sketchName
'Dim docOpen = ivExe.Documents.Open(oPartDoc.ReferencedDocumentDescriptor.FullDocumentName)
End If
Else 'No dervied Parts
oExistisSketches = oPartDoc.Definition.Document.ComponentDefinition.Sketches
For s = 1 To oExistisSketches.Count
If oExistisSketches.Item(s).Name = sketchName Then
sketchCounter += 1
sketchName = "Sketch_" & sketchCounter
End If
Next
If Sketchface.SurfaceType = SurfaceTypeEnum.kPlaneSurface Then
oSketch = oPartDoc.Definition.Document.ComponentDefinition.Sketches.Add(Sketchface.NativeObject)
oSketch.Name = sketchName
End If
End If
End Function
Thank you!