Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Use iLogic To Create Assembly

Anonymous

Use iLogic To Create Assembly

Anonymous
Not applicable

I constantly have to make a large number of very similar parts and then make a drawing that has them all in it. This is generally done by throwing all the files into an assembly and using that as the main base for the drawing, as the title block displays total weight and other properties that would not show up if you put the parts in one at a time. So onto the question:

 

I have made a builder to make the parts and save them automatically. What I then want is to create an assembly file from the Part iLogic and place selected files loose into it. Anyone have any ideas on how to do this? I cannot find any other discussions on creating assembly files

0 Likes
Reply
2,848 Views
5 Replies
Replies (5)

HermJan.Otterman
Advisor
Advisor

hello  lukergrt

 

 

Private Sub CreateAssy()

  Dim oApp As Application = ThisApplication

  Dim oAssyDoc As Inventor.AssemblyDocument = oApp.Documents.Add(DocumentTypeEnum.kAssemblyDocumentObject, "C:\...FullPath....\standard.iam")

 

End Sub

 

this should work

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


MechMachineMan
Advisor
Advisor

Or try something along these lines (from API samples)

 

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

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

    ' Create a matrix.  A new matrix is initialized with an identity matrix.
    Dim oMatrix As Matrix
    Set 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
    Set oOcc = oAsmCompDef.Occurrences.Add("C:\Temp\Part1.ipt", oMatrix)
End Sub

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type

JBerns
Advisor
Advisor

I was reviewing the original post by @Anonymous in which I interpreted that he wanted to create a new assembly and then add components to it.

 

@HermJan.Otterman explained how to create a new assembly. @MechMachineMan explained how to add components to an existing assembly.

 

My question - how do you make the new assembly as the existing (active) assembly in which to add the new components?

 

Here is the code I have so far. You will need to substitute your template path and component as needed:

Sub Main()

	' Create and activate new assembly
	Dim oTemplatePath = "Z:\Inventor_Data\Templates\"
	Dim oAssembly As AssemblyDocument
	oAssembly = ThisApplication.Documents.Add(kAssemblyDocumentObject, oTemplatePath & "MY_ASSEMBLY.iam", True)
	oAssembly.Activate

	' Insert and name Comp_01
	Dim componentA = Components.Add("Comp_01", "ABC123.ipt", position := Nothing, grounded := False, visible := True, appearance := Nothing)

End Sub

 

The above code errors if run from a part:

Error in rule: ThisAssembly: This document "Part2" is not an assembly.

 

When run from an open assembly, a new assembly is created, but the component is added in the first assembly document, NOT the new assembly.

 

I hope someone can offer a solution. A workaround would be to ask the user to create a new assembly with the required template before running the code.

 

Thanks for your time. I look forward to the responses.

 

 

Regards,

Jerry

 

-----------------------------------------------------------------------------------------
CAD Administrator
Using Inventor 2022
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes

Anonymous
Not applicable

Hey Jerry,

 

The way I ended up doing this was by saving a template assembly that was empty, but had the ilogic code programmed to add the parts I wanted on startup.

 

Then from your current assembly (or in my case it was a part file) run code to just open that template

 

In my case that was this:

'Open Assembly File
	ThisDoc.Launch("S:\Engineering\Inventor\Styles and Standards\Templates\iLogic-Conduit-ASM.iam")

 

As soon as that opens all the ilogic programmed to run on startup kicks in and treats that assembly as active to place everything.

 

Hopefully this helps, can provide some more specific code from my scenario if needed, but I suspect it won't be directly relatable.

 

Cheers,

Luke

 

0 Likes

JBerns
Advisor
Advisor

@Anonymous,

 

Thanks for the quick reply and the info. It will be useful.

I remain curious if it is possible to create a new assembly and place components in the assembly.

Perhaps this can't be done from an iLogic rule, but instead using API in an external program.

 

Thanks again.

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using Inventor 2022
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes