Community
I have a similar problem. In my macro, when I select a face on the part (in assembly) I gets Faceproxy object. According to Brian instruction, to create a sketch in the new part I use the NativeObject and ...
does not work.
What am I doing wrong?
Here is my code:
' Check to make sure a Assembly document is active.
If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject Then
MsgBox "A assembly document must be active."
Exit Sub
End If
' Set a reference to the active document.
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument
'Select Face in Assembly
Dim oSelect As New clsSelect
Dim oFace As face
Set oFace = oSelect.Pick(kPartFaceFilter) 'kWorkPlaneFilter
Dim oNativeFace As face
If oFace Is Nothing Then
Exit Sub
Else
Set oNativeFace = oFace.NativeObject
End If
'Create the new part
Dim oPart As PartDocument
Set oPart = ThisApplication.Documents.Add(kPartDocumentObject, ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject), False)
oPart.FullFileName = Mid(oDoc.FullFileName, 1, InStrRev(oDoc.FullFileName, "\")) & "InB-1.ipt"
' Set a reference to the transient geometry object.
Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry
'Insert the part into the assembly using a somewhat 0 position.
Set oMatrix = oTG.CreateMatrix
Call oMatrix.Translation.AddVector(oTG.CreateVector(0, 0, 0))
Call oMatrix.SetToRotation(0, oTG.CreateVector(0, 0, 0), oTG.CreatePoint(0, 0, 0))
Dim oOcc As ComponentOccurrence
Set oOcc = oDoc.ComponentDefinition.Occurrences.AddByComponentDefinition(oPart.ComponentDefinition, oMatrix)
Dim oSketch As PlanarSketch
Set oSketch = oPart.ComponentDefinition.Sketches.Add(oNativeFace, True)