I'm trying to use the PlanarSketch.AddBySilhouette method to project a collection of faces found with AssemblyComponentDefinition.FindUsingRay, but I get an error when trying to create the sketch entity.
Has anyone successfully implemented this method? I can run the help file code example w/out error, but it's being used in a part document. Is it possible this just doesn't work at the assembly level? Forum search for AddBySilhouette pulls up absolutely nothing. Code below.
Dim oDoc As AssemblyDocument Set oDoc = ThisDocument Dim oACD As AssemblyComponentDefinition Set oACD = oDoc.ComponentDefinition Dim oTG As TransientGeometry Set oTG = ThisApplication.TransientGeometry Dim oSk As PlanarSketch Set oSk = oACD.Sketches.Item("Rotating Sketch") Dim oPart As ComponentOccurrence Dim oBody As SurfaceBody Dim startPt As Point Set startPt = oTG.CreatePoint(0, 0, 0) 'create a vector facing the sketch from the origin Dim oVecPt As WorkPoint Set oVecPt = oACD.WorkPoints.Item("VectorPoint") Dim pt As Point Set pt = oVecPt.Point Dim oVec As UnitVector Set oVec = oTG.CreateUnitVector(pt.X, pt.Y, pt.Z) Dim objCol As ObjectsEnumerator Dim ptCol As ObjectsEnumerator Call oACD.FindUsingRay(startPt, oVec, 1, objCol, ptCol, False) Dim proxPt As Point Dim oFoundItem As Object Dim oSkEnt As SketchEntity Dim oFace As Face For Each oFoundItem In objCol If oFoundItem.Type = kFaceProxyObject Then Set oFace = oFoundItem.NativeObject Set proxPt = oFace.PointOnFace ' ERROR GENERATED BY THE LINE BELOW Set oSkEnt = oSk.AddBySilhouette(oFace, proxPt) End If Next end Sub
My thoughts:
My use of the 'ProximityPoint' input could be blatantly wrong, I couldn't really glean its proper use from the code example.
or
Using the Face object in the method at the assembly level doesn't work (but neither does the FaceProxy object, unfortunately).
Appreciate any help. Thanks.
Hi,
Try using a PlanarSketchProxy. Here is a VBA example I have:
Public Sub ProjectAssemEdge()
' get assembly document
Dim asmDoc As AssemblyDocument
Set asmDoc = ThisApplication.ActiveDocument
' get myHole from first part
Dim occ1 As ComponentOccurrence
Set occ1 = asmDoc.ComponentDefinition.Occurrences.Item(1)
Dim partDef1 As PartComponentDefinition
Set partDef1 = occ1.Definition
Dim oProxyEdge As Edge
Dim oEdge As Edge
For Each oEdge In asmDoc.ComponentDefinition.Occurrences(1).SurfaceBodies(1).Edges
If oEdge.CurveType = kCircleCurve Then
Set oProxyEdge = oEdge
End If
Next
' get mySketch from second part
Dim occ2 As ComponentOccurrence
Set occ2 = asmDoc.ComponentDefinition.Occurrences.Item(2)
Dim partDef2 As PartComponentDefinition
Set partDef2 = occ2.Definition
Dim mySketch As PlanarSketch
Set mySketch = partDef2.Sketches.Item(1)
Dim mySketchProxy As PlanarSketchProxy
occ2.CreateGeometryProxy mySketch, mySketchProxy
' try to project edge in mySketch
Dim projEdge As SketchEntity
Set projEdge = mySketchProxy.AddByProjectingEntity(oProxyEdge)
End Sub
Thanks,
Wayne
Hi,
The first thing you would need to do in such a case is check if it's possible in the user interface. 🙂
It does not seem to be. It seems that you can only project edges but not faces into the assembly sketch.
The API must have the same limitation then.
Cheers,