Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can someone share how to automatically make part files when outside of inventor options are chosen?

6 REPLIES 6
Reply
Message 1 of 7
chris
307 Views, 6 Replies

Can someone share how to automatically make part files when outside of inventor options are chosen?

I keep seeing these add-on packages where they are using Excel or some other type of "form" where you can choose options and when they hit "launch" or "execute", it just opens an Inventor part or assembly and builds the geometry.

 

How is this done or what steps can I take to start to understand or demo this?

6 REPLIES 6
Message 2 of 7
A.Acheson
in reply to: chris

Hi @chris 

Well the world is your oyster when it comes to automating tasks in inventor. where would you like to start? 

 

The API help samples has powerful examples of all types of automation and the only thing they don't have is the interaction with excel. It can all depend on how flexible you want the options to be for the user. Are you just building parts into an assembly and constraining or are you just changing options of an existing assembly or are you trying to draw a part from scratch which would likely be the most difficult.

 

Just name a simple task you want to start with and I can likely guide you to resource to learn how it's done. 

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 7
chris
in reply to: chris

@A.Acheson Example, I create a bunch of "advanced templates" that I use to help automate repetitive work, usually with an iLogic form that opens once the template is launched, and that works great for single parts or multi-body parts, but recently I've had a few projects come up that would require several parts to be created and constrained into an assembly and I know it can be done as I see it a lot with a software called "SEG" used with Inventor.

 

I'm really just curious as to how it happens and how I might be able to use it for the smaller things I create, not to mention it's totally cool.

Reference: (32:00)

Message 4 of 7
chris
in reply to: chris

@A.Acheson Here's another question, let's say I create a sketch on the XZ plane, (Y is up), of a circle that is 120" in diameter and extruded "up" 70".

Where or how do I access the commands that told Inventor to perform those sets of instructions in that order?

Message 5 of 7
A.Acheson
in reply to: chris

iLogic API

To start with the ilogic API can easily automate the manual constraining and adding of parts. Simply build the assembly and go to the editor and right click the components and capture constraints and components added. This is kinda similar to a macro recorder. So this is where I would start as it is an entry level start to complex multilevel constraints. 

Inventor API

The same operations can be done with the Inventor API but this will involve you coding everything manually. These samples are for VBA and below the conversion to VB.NET for use in the ilogic environment. For the most part just drop the word ''Set'' and it will work in ilogic. 

 

See sample here to add an occurrence.

 

Sub Main
		Dim filename As String = "C:\Temp\Part1.ipt"
		AddOccurrence(filename)
End Sub

Public Sub AddOccurrence(filename As String)
    ' Set a reference to the assembly component definintion.
    ' This assumes an assembly document is open.
    Dim oAsmCompDef As AssemblyComponentDefinition
   oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

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

    ' Create a matrix.  A new matrix is initialized with an identity matrix.
    Dim oMatrix As Matrix
    oMatrix = oTG.CreateMatrix

    ' Set the rotation of the matrix for a 45 degree rotation about the Z axis.
    Call oMatrix.SetToRotation(3.14159265358979 / 4, _
                            oTG.CreateVector(0, 0, 1), oTG.CreatePoint(0, 0, 0))

    ' Set the translation portion of the matrix so the part will be positioned
    ' at (3,2,1).
    Call oMatrix.SetTranslation(oTG.CreateVector(3, 2, 1))

    ' Add the occurrence.
    Dim oOcc As ComponentOccurrence
    oOcc = oAsmCompDef.Occurrences.Add(filename, oMatrix)
End Sub

 

See sample here to constrain occurrences.

 

Sub Main
	MateConstraintOfWorkPlanes()
End Sub

Public Sub MateConstraintOfWorkPlanes()
    Dim oAsmCompDef As AssemblyComponentDefinition
    oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

    ' Get references to the two occurrences to constrain.
    ' This arbitrarily gets the first and second occurrence.
    Dim oOcc1 As ComponentOccurrence
    oOcc1 = oAsmCompDef.Occurrences.Item(1)

    Dim oOcc2 As ComponentOccurrence
    oOcc2 = oAsmCompDef.Occurrences.Item(2)

    ' Get the XY plane from each occurrence.  This goes to the
    ' component definition of the part to get this information.
    ' This is the same as accessing the part document directly.
    ' The work plane obtained is in the context of the part,
    ' not the assembly.
    Dim oPartPlane1 As WorkPlane
    oPartPlane1 = oOcc1.Definition.WorkPlanes.Item(3)

    Dim oPartPlane2 As WorkPlane
    oPartPlane2 = oOcc2.Definition.WorkPlanes.Item(3)

    ' Because we need the work plane in the context of the assembly
    ' we need to create proxies for the work planes.  The proxies
    ' represent the work planes in the context of the assembly.
    Dim oAsmPlane1 As WorkPlaneProxy
    Call oOcc1.CreateGeometryProxy(oPartPlane1, oAsmPlane1)

    Dim oAsmPlane2 As WorkPlaneProxy
    Call oOcc2.CreateGeometryProxy(oPartPlane2, oAsmPlane2)

    ' Create the constraint using the work plane proxies.
    Call oAsmCompDef.Constraints.AddMateConstraint(oAsmPlane1, oAsmPlane2, 0)
End Sub

 

 

As regard creating parts you first have to start with having a solid knowledge of how the part was created and also I guess does it justify your time to code in the part creation over doing it yourself in the UI. I guess it comes down to what you need to do.

 

Sub Main
	CreateAllRoundsFillet()
End Sub
Public Sub CreateAllRoundsFillet()
    ' Create a new Part document.
    Dim oPartDoc As PartDocument
   oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, _
                 ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject))
    
    ' Set a reference to the compdef.
    Dim oCompDef As PartComponentDefinition
    oCompDef = oPartDoc.ComponentDefinition
    
    ' Create a sketch on the xy work plane.
    Dim oSketch As PlanarSketch
   oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes.Item(3))
    
    ' Draw a rectangle.
    Call oSketch.SketchLines.AddAsTwoPointRectangle( _
                            ThisApplication.TransientGeometry.CreatePoint2d(-6, -4), _
                            ThisApplication.TransientGeometry.CreatePoint2d(6, 4))
                                                
    Dim oProfile As Profile
    oProfile = oSketch.Profiles.AddForSolid
    
    ' Create an extrusion.
    Dim oExtrudeDef As ExtrudeDefinition
    oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kJoinOperation)
    Call oExtrudeDef.SetDistanceExtent(5, kSymmetricExtentDirection)
    Dim oExtrude As ExtrudeFeature
    oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)

    ' Declare an EdgeCollection object to pass in since it is a required argument,
    ' but since we're going to specify all rounds, we don't need to actually create
    ' the EdgeCollection or add any edges to it.
    Dim oEdges As EdgeCollection
        
    ' Create the fillet feature specifying to do all rounds.
    Dim oFillet As FilletFeature
    oFillet = oCompDef.Features.FilletFeatures.AddSimple(oEdges, 1, , True)
End Sub

 

.

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 6 of 7
A.Acheson
in reply to: chris

This sample below is just put together in notepad so it isn't tested and there might see some bugs for you to find.  I modified the API sample posted earlier. I have marked your points with numbers which you can follow through the code. If you need to find new objects navigate up and down the objects list and find the objects your looking for and your unsure of objects names they can some times match the dialogue boxes in the UI and so you can search the help page for the object. I find the built in API help .chm file is great for this as the online help file can bring up samples alot and might hinder you from advancing. 

 

 

(1)sketch on the XZ plane,
https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=WorkPlanes_Item
https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=PlanarSketches_Add
(2)circle that is 120" in diameter
https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=SketchCircles_AddByCenterRadius
(3)extruded "up" 70".
https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=ExtrudeDefinition_SetDistanceExtent
https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=PartFeatureExtentDirectionEnum

 

 

 

Sub Main
	CreateExtrusion
End Sub
Public Sub CreateAllRoundsFillet()
    ' Create a new Part document.
    Dim oPartDoc As PartDocument
   oPartDoc = ThisApplication.ActiveDocument
    
    ' Set a reference to the compdef.
    Dim oCompDef As PartComponentDefinition
    oCompDef = oPartDoc.ComponentDefinition
    
    ' (1)Create a sketch on the XZ work plane. You can give it an index number or a name helpful if you are using custom workplanes
    Dim oSketch As PlanarSketch
   oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes.Item("XZ Plane")
    
    ' Get centerpoint location
    Dim oCenterPt as Point2d =  ThisApplication.TransientGeometry.CreatePoint2d(0, 0)
  
  ' (2)Draw a circle.
  oSketch.SketchCircles.AddByCenterRadius(oCenterPt, ((120/2)*2.54) ) As SketchCircle
                                                
    Dim oProfile As Profile
    oProfile = oSketch.Profiles.AddForSolid
    
    ' Create an extrusion.
    Dim oExtrudeDef As ExtrudeDefinition
    oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kJoinOperation)
    
	'Set distance and direction
	Call oExtrudeDef.SetDistanceExtent(70*2.54, kPositiveExtentDirection)
    
	Dim oExtrude As ExtrudeFeature
    oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)

End Sub

 AAcheson_0-1714104882078.png

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 7 of 7
Michael.Navara
in reply to: chris

Create model from scratch is very hard task. It requires lot of experiences and lot of time.

Below are some links to our projects we delivered to our customers. All of them are based on Inventor, APS (Forge) and WEB APIs.

 

Video: 

https://www.youtube.com/watch?v=lMaUntwpMSE

 

Live demo: 

https://app-platformdemo-dev.azurewebsites.net/

https://csgate.azurewebsites.net/?lang=en

 

 

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

Post to forums  

Autodesk Design & Make Report