VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Reply
Message 1 of 1
Anonymous
186 Views, 0 Replies

TrimSolid

I have an error at the end of command. Please help me.

 

My work is trim a solid with a plane

 

 

Public Sub DrawBlockWithPocket()
' Create a new part document, using the default part template.
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, _
ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject))

' Set a reference to the component definition.
Dim oCompDef As PartComponentDefinition
Set oCompDef = oPartDoc.ComponentDefinition

' Create a new sketch on the X-Y work plane. Since it's being created on
' one of the base workplanes we know the orientation it will be created in
' and don't need to worry about controlling it. Because of this we also
' know the origin of the sketch plane will be at (0,0,0) in model space.
Dim oSketch As PlanarSketch
Set oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes(3))

' Set a reference to the transient geometry object.
Dim oTransGeom As TransientGeometry
Set oTransGeom = ThisApplication.TransientGeometry

' Draw a 4cm x 3cm rectangle with the corner at (0,0)
Dim oRectangleLines As SketchEntitiesEnumerator
Set oRectangleLines = oSketch.SketchLines.AddAsTwoPointRectangle(oTransGeom.CreatePoint2d(0, 0), oTransGeom.CreatePoint2d(6, 6))

' Create a profile.
Dim oProfile As Profile
Set oProfile = oSketch.Profiles.AddForSolid

' Create a base extrusion 1cm thick.
Dim oExtrude As ExtrudeFeature
Set oExtrude = oCompDef.Features.ExtrudeFeatures.AddByDistanceExtent(oProfile, 6, kNegativeExtentDirection, kJoinOperation)



''''''''''''''''''Generate Line
'Dim oPartDoc As PartDocument
'Set oPartDoc = ThisApplication.ActiveDocument

'Dim oCompDef As PartComponentDefinition
'Set oCompDef = oPartDoc.ComponentDefinition

Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry



Dim oWPs(1 To 5) As WorkPoint
Set oWPs(1) = oCompDef.WorkPoints.AddFixed(oTG.CreatePoint(1, 1, 1))
Set oWPs(2) = oCompDef.WorkPoints.AddFixed(oTG.CreatePoint(2, 2, 2))
Set oWPs(3) = oCompDef.WorkPoints.AddFixed(oTG.CreatePoint(3, 4, 0))
Set oWPs(4) = oCompDef.WorkPoints.AddFixed(oTG.CreatePoint(3, 4, 2))
Set oWPs(5) = oCompDef.WorkPoints.AddFixed(oTG.CreatePoint(6, 4, 2))

' 3D Sketch.
Dim oSketch3D As Sketch3D
Set oSketch3D = oPartDoc.ComponentDefinition.Sketches3D.Add


Dim oLine As SketchLine3D
Set oLine = oSketch3D.SketchLines3D.AddByTwoPoints(oWPs(1), oWPs(2), True, 1)


Dim oWP As WorkPlane
Set oWP = oCompDef.WorkPlanes.AddByNormalToCurve(oLine, oLine.EndSketchPoint)


'''''Cut solid by the planes
Dim oSplit As SplitFeature
Set oSplit = oCompDef.Features.SplitFeatures.TrimSolid(oWP, oExtrude, True)
End Sub

0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost