Hello,
I am trying to make iLogic script what will create new part then sketch on plane based on user input, project axes and middle point, draw rectanlge or circle get dimmensions to it and make surface or extrusion. I can create new part, is it possible to create directly sheet metal part? make sketch based on user input but im stucked on projecting axes and creating rectanlge, getting various errors from compiler.
Any help would be appreccieted.
' Connect to a running instance of Inventor. Dim invApp As Inventor.Application invApp = System.Runtime.InteropServices.Marshal.GetActiveObject _ ("Inventor.Application") ' Get the Documents collection. Dim docs As Inventor.Documents = invApp.Documents ' Create a new part document. Dim partDoc As Inventor.PartDocument partDoc = docs.Add(Inventor.DocumentTypeEnum.kPartDocumentObject) ' Get the component definition. Dim partDef As Inventor.PartComponentDefinition partDef = partDoc.ComponentDefinition ' Get the X-Y work plane. Dim xyPlane As Inventor.WorkPlane = partDef.WorkPlanes.Item(3) ' Get the X-Y work plane. Dim xzPlane As Inventor.WorkPlane = partDef.WorkPlanes.Item(2) ' Get the X-Y work plane. Dim zyPlane As Inventor.WorkPlane = partDef.WorkPlanes.Item(1) ' Select work plane. Dim n As Integer 'n = InputBox("Vyberte pracovní rovinu" & " " & "XY = 3" & " " & "XZ = 2" & " " & "ZY = 1","iLogic Work Plane","") n = InputBox ("Vyberte pracovní rovinu: " & Name _ & vbLf & "XY = 3" & ShortName _ & vbLf & "XZ = 2" & Folder_Location _ & vbLf & "ZY = 1" & CurFileName, "iLogic Work Plane") ' Create a new sketch. Dim Sketch As Inventor.PlanarSketch Sketch = partDef.Sketches.Add(partDef.WorkPlanes.Item(n), False) ' Project the origin point onto the sketch. Dim oOriginSketchPoint As SketchPoint = Sketch.AddByProjectingEntity(PartDef.WorkPoints.Item(1))
After few more hours of research...
Sub Main() ' Connect to a running instance of Inventor. Dim invApp As Inventor.Application invApp = System.Runtime.InteropServices.Marshal.GetActiveObject _ ("Inventor.Application") ' Get the Documents collection. Dim docs As Inventor.Documents = invApp.Documents ' Create a new part document. Dim partDoc As Inventor.PartDocument partDoc = docs.Add(Inventor.DocumentTypeEnum.kPartDocumentObject) ' Get the component definition. Dim partDef As Inventor.PartComponentDefinition partDef = partDoc.ComponentDefinition 'example UnitsTypeEnum Enumerators 'kCentimeterLengthUnits = 11268 'kMillimeterLengthUnits = 11269 'kInchLengthUnits = 11272 'kKilogramMassUnits = 11283 'kGramMassUnits = 11284 'kLbMassMassUnits = 11286 ' Set a reference to the UnitsOfMeasure object of the ' active document. Dim oUOM As UnitsOfMeasure = ThisApplication.ActiveDocument.UnitsOfMeasure oUOM.LengthUnits = 11269 'oUOM.GetStringFromValue(dVolume, _ 'oUOM.GetStringFromType(oUOM.LengthUnits) & "^3") 'kMilimeterLengthUnits oUOM.LengthDisplayPrecision = 4 ' Get the X-Y work plane. Dim xyPlane As Inventor.WorkPlane = partDef.WorkPlanes.Item(3) ' Get the X-Y work plane. Dim xzPlane As Inventor.WorkPlane = partDef.WorkPlanes.Item(2) ' Get the X-Y work plane. Dim zyPlane As Inventor.WorkPlane = partDef.WorkPlanes.Item(1) ' Select work plane. Dim n As Integer 'n = InputBox("Vyberte pracovní rovinu" & " " & "XY = 3" & " " & "XZ = 2" & " " & "ZY = 1","iLogic Work Plane","") n = InputBox ("Vyberte pracovní rovinu: " & Name _ & vbLf & "XY = 3" & ShortName _ & vbLf & "XZ = 2" & Folder_Location _ & vbLf & "ZY = 1" & CurFileName, "iLogic Work Plane") ' Create a new sketch. Dim Sketch As Inventor.PlanarSketch Sketch = partDef.Sketches.Add(partDef.WorkPlanes.Item(n), False) 'n = InputBox("Vyberte pracovní rovinu" & " " & "XY = 3" & " " & "XZ = 2" & " " & "ZY = 1","iLogic Work Plane","") Dim FileType As Integer FileType = InputBox ("Vyberte typ souboru: " & vbNewFile _ & vbLf & "Plech : 1" & ShortName _ & vbLf & "Součást : 2" & CurFileName, "iLogic File Type") If FileType = 1 Then ' set file sub type to sheet metal If partDoc.subtype <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then partDoc.subtype = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" End If Else If FileType = 2 Then ' set file sub type to part If partDoc.subtype <> "{4D29B490-49B2-11D0-93C3-7E0706000000}" Then partDoc.subtype = "{4D29B490-49B2-11D0-93C3-7E0706000000}" End If End If ' Project the origin point onto the sketch. Dim oOriginSketchPoint As SketchPoint = Sketch.AddByProjectingEntity(PartDef.WorkPoints.Item(1)) 'Edit sketch Sketch.edit ' Project the origin axis onto the sketch. ' The origin planes are the first 3 ' in the WorkPlanes collection Dim i As Integer For i = 1 To 3 Dim wp As WorkPlane = partDef.WorkPlanes(i) ' If the WorkPlane was already added ' then AddByProjectingEntity would throw ' an error. ' To avoid that we can do error handling: On Error Resume Next If wp.Plane.IsPerpendicularTo(Sketch.PlanarEntityGeometry) Then ' Checking if the workplane is perpendicular might ' be an overkill because if not, then the below ' function would throw an error. ' But I think it's nicer if we check :) Call Sketch.AddByProjectingEntity(wp) ' Make the line a construction line 'wp.Construction = True End If On Error Goto 0 Next i ' Create a rectangle. in 0.0 'Call Sketch.SketchLines.AddAsTwoPointRectangle(oOriginSketchPoint, ThisApplication.TransientGeometry.CreatePoint2d(20, 10)) 'AddAsTwoPointRectangle (corner point one: the origin sketch point, corner point two: point 20,10) ' Set a reference to the transient geometry object. Dim oTransGeom As TransientGeometry = ThisApplication.TransientGeometry ' Create a rectangle On the Sketch. Call Sketch.SketchLines.AddAsTwoPointRectangle(ThisApplication.TransientGeometry.CreatePoint2d(-20, -10), ThisApplication.TransientGeometry.CreatePoint2d(20, 10)) End Sub
Still looking for make all axes as "construction" if i use "wp.construction = ture" im getting read only error.
How to make it symmetrical around both axes.
Add dimmensions from user input.
Make it steel plate (surface not extrude).