Hello,
I'm new using this forum. So feel free to let me know if this is answered. I could not find it.
I've made a link to excel that gets values from the cells I will use to set the offset value from work plan XY. How can I use iLogic to define a new work plan with this value as an offset?
best regard,
Lewi
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Hi lub,
Here is a quick example:
oDef = ThisDoc.Document.ComponentDefinition Dim oWPlane As WorkPlane oWPlane = oDef.WorkPlanes.AddByPlaneAndOffset(oDef.WorkPlanes("XY Plane"), 2 cm) oWPlane.Name = "My_New_Work_Plane"
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
You would not happen to know how I get to add a sketch to this work plane in another rule?
I’ve tried different things, but I can’t get it to work properly. I get it to work if I do it in the same rule, but that is not my wish.
Different rule:
SyntaxEditor Code Snippet
oSketch = oDef.Sketches.Add(WorkPlane("P-Framenumber_0_Z_Value")) osketch.Name = "S-" & FrameNumberName
Same Rule:
SyntaxEditor Code Snippet
oDef = ThisDoc.Document.ComponentDefinition Dim oWPlane As WorkPlane Dim oSketch As PlanarSketch oWPlane = oDef.WorkPlanes.AddByPlaneAndOffset(oDef.WorkPlanes("XY Plane"), FrameNumberName) oWPlane.Name = "P-" & FrameNumberName oSketch = oDef.Sketches.Add(oWPlane) osketch.Name = "S-" & FrameNumberName
Hi lub,
Assuming the variable called "FrameNumberName" is known in the second rule, you can just call the define the workplane by name as in this example:
oDef = ThisDoc.Document.ComponentDefinition Dim oSketch As PlanarSketch Dim oWPlane As WorkPlane oWPlane = oDef.WorkPlanes.Item("P-" & FrameNumberName) oSketch = oDef.Sketches.Add(oWPlane) osketch.Name = "S-" & FrameNumberName
oSketch.Edit
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Curtis,
Would this be done the same way in vb.net? It keeps throwing an "Unspecified Error".
Thanks,
JG
Curtis!
As in the logic to do the following: construction of the normal plane to the segment, draw the outline: the outer diameter of the pipe thickness. To thicknesses and diameters could be listed and make new ones. and was designed to sweep length, entered into a variable (here you can tie the old rule Thesweep). And if you can assign the material type.
Is it real?
Best regards!
vyivanchikov@ya.ru
Hi vyivanchikov,
If I understand correctly, the question is how to create a workplane at the end of a sketch line, and then use that to create a sketch, from which to create a sweep.
The short answer involves something like this example:
' Create a work plane at the end of the 2D sketch.
Dim oWP As WorkPlane
oWP = oCompDef.WorkPlanes.AddByNormalToCurve _
(oSketchLine2, oSketchLine2.EndSketchPoint)
But here is some iLogic code from which the above was taken, that is based on the Autodesk Inventor COM API VB samples. This code will create an entire sweep automatically:
' a reference to the currently active document.
' This assumes that it is a part document.
Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument
' a reference to the component definition.
Dim oCompDef As PartComponentDefinition
oCompDef = oPartDoc.ComponentDefinition
' a reference to the transient geometry object.
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
' Create some workpoints that will be used for the 3D sketch.
Dim oWPs(0 To 4) As WorkPoint
oWPs(0) = oCompDef.WorkPoints.AddFixed(oTG.CreatePoint(0, 0, 0))
oWPs(1) = oCompDef.WorkPoints.AddFixed(oTG.CreatePoint(3, 0, 0))
oWPs(2) = oCompDef.WorkPoints.AddFixed(oTG.CreatePoint(3, 4, 0))
oWPs(3) = oCompDef.WorkPoints.AddFixed(oTG.CreatePoint(3, 4, 2))
oWPs(4) = oCompDef.WorkPoints.AddFixed(oTG.CreatePoint(6, 4, 2))
' Create a new 3D Sketch.
Dim oSketch3D As Sketch3D
oSketch3D = oPartDoc.ComponentDefinition.Sketches3D.Add
' Draw 3D lines. The first line is drawn between two of the work points.
Dim oLine As SketchLine3D
oLine = oSketch3D.SketchLines3D.AddByTwoPoints(oWPs(0), oWPs(1), True, 1)
' This second and subsequent lines are drawn between a 3D
' sketch point and a work point.
' The work point is obtained from the previous line.
' Because the two lines will share
' this 3D sketch point, Inventor will treat them as
' connected lines when creating any paths.
oLine = oSketch3D.SketchLines3D.AddByTwoPoints _
(oLine.EndPoint, oWPs(2), True, 1)
oLine = oSketch3D.SketchLines3D.AddByTwoPoints _
(oLine.EndPoint, oWPs(3), True, 0.75)
oLine = oSketch3D.SketchLines3D.AddByTwoPoints _
(oLine.EndPoint, oWPs(4), True, 1)
' Create a 2D sketch.
Dim oSketch As PlanarSketch
oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes.Item(2))
' Determine the model origin relative to the sketch space.
Dim oOrigin As Point2d
oOrigin = oSketch.ModelToSketchSpace(oTG.CreatePoint(0, 0, 0))
' Create two lines.
Dim oNewPoint As Point2d
oNewPoint = oTG.CreatePoint2d(oOrigin.X, oOrigin.Y - 4)
Dim oSketchLine1 As SketchLine
oSketchLine1 = oSketch.SketchLines.AddByTwoPoints(oOrigin, oNewPoint)
oNewPoint.X = oNewPoint.X + 3
Dim oSketchLine2 As SketchLine
oSketchLine2 = oSketch.SketchLines.AddByTwoPoints _
(oSketchLine1.EndSketchPoint, oNewPoint)
' Create a fillet between the two lines.
Call oSketch.SketchArcs.AddByFillet(oSketchLine1, oSketchLine2, 1, _
oSketchLine1.StartSketchPoint.Geometry, oSketchLine2.EndSketchPoint.Geometry)
' Get the end of the 2d sketch in model space.
Dim oModelPoint As Point
oModelPoint = oSketch.SketchToModelSpace _
(oSketchLine2.EndSketchPoint.Geometry)
' Create a work plane at the end of the 2D sketch.
Dim oWP As WorkPlane
oWP = oCompDef.WorkPlanes.AddByNormalToCurve _
(oSketchLine2, oSketchLine2.EndSketchPoint)
' Create a path. Because the 3D and 2D sketches physically
' connect the path will include both of them.
Dim oPath As Path
oPath = oCompDef.Features.SweepFeatures.CreatePath(oSketchLine2)
' Create a sketch containing a circle.
oSketch = oCompDef.Sketches.Add(oWP)
oOrigin = oSketch.ModelToSketchSpace(oTG.CreatePoint(0, 0, 0))
Call oSketch.SketchCircles.AddByCenterRadius _
(oSketch.ModelToSketchSpace(oModelPoint), 0.375)
' Create a profile.
Dim oProfile As Profile
oProfile = oSketch.Profiles.AddForSolid
' Create the sweep feature.
Dim oSweep As SweepFeature
oSweep = oCompDef.Features.SweepFeatures.AddUsingPath _
(oProfile, oPath, kJoinOperation)
Here is another version that creates a sweep with only a 2D sketch path and another 2D sketch for the profile, in case it is easier to understand:
' a reference to the currently active document. ' This assumes that it is a part document. Dim oPartDoc As PartDocument oPartDoc = ThisApplication.ActiveDocument ' a reference to the component definition. Dim oCompDef As PartComponentDefinition oCompDef = oPartDoc.ComponentDefinition ' a reference to the transient geometry object. Dim oTG As TransientGeometry oTG = ThisApplication.TransientGeometry ' Create a 2D sketch. Dim oSketch As PlanarSketch oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes.Item(2)) ' Determine the model origin relative to the sketch space. Dim oOrigin As Point2d oOrigin = oSketch.ModelToSketchSpace(oTG.CreatePoint(0, 0, 0)) ' Create two lines. Dim oNewPoint As Point2d oNewPoint = oTG.CreatePoint2d(oOrigin.X, oOrigin.Y - 4) Dim oSketchLine1 As SketchLine oSketchLine1 = oSketch.SketchLines.AddByTwoPoints(oOrigin, oNewPoint) oNewPoint.X = oNewPoint.X + 3 Dim oSketchLine2 As SketchLine oSketchLine2 = oSketch.SketchLines.AddByTwoPoints _ (oSketchLine1.EndSketchPoint, oNewPoint) ' Create a fillet between the two lines. Call oSketch.SketchArcs.AddByFillet(oSketchLine1, oSketchLine2, 1, _ oSketchLine1.StartSketchPoint.Geometry, oSketchLine2.EndSketchPoint.Geometry) ' Get the end of the 2d sketch in model space. Dim oModelPoint As Point oModelPoint = oSketch.SketchToModelSpace _ (oSketchLine2.EndSketchPoint.Geometry) ' Create a work plane at the end of the 2D sketch. Dim oWP As WorkPlane oWP = oCompDef.WorkPlanes.AddByNormalToCurve _ (oSketchLine2, oSketchLine2.EndSketchPoint) oWP.visible = False ' Create a path. Because the 3D and 2D sketches physically ' connect the path will include both of them. Dim oPath As Path oPath = oCompDef.Features.SweepFeatures.CreatePath(oSketchLine2) ' Create a sketch containing a circle. oSketch = oCompDef.Sketches.Add(oWP) oOrigin = oSketch.ModelToSketchSpace(oTG.CreatePoint(0, 0, 0)) Call oSketch.SketchCircles.AddByCenterRadius _ (oSketch.ModelToSketchSpace(oModelPoint), 0.375) ' Create a profile. Dim oProfile As Profile oProfile = oSketch.Profiles.AddForSolid ' Create the sweep feature. Dim oSweep As SweepFeature oSweep = oCompDef.Features.SweepFeatures.AddUsingPath _ (oProfile, oPath, kJoinOperation)
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com