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: 

iLogic Copy Assembly, Rename, and Place into New Assembly

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Anonymous
2895 Views, 5 Replies

iLogic Copy Assembly, Rename, and Place into New Assembly

Okay... This morning I thought I had a nice, clear plan in my head of how to get this done, and then I didn't. Ain't nothin' easy!

 

DISCLAIMER: I have just enough experience programming (not in VB) to get me into trouble.

 

I found a nice snippet of iLogic code that allows me to copy an assembly, rename it via dialog box, and choose a new location to save the assembly and all associated parts. That gets me part of the way to where I want to be, but, first, I can't seem to run that as an external rule on a file opened silently. It just wants to run on the assembly I have open at the time (I understand why this is, I had just hoped it would see the silently opened file as the active file or at least use it if using ThisDoc.Document). I was hoping to leave iLogic mostly out of the assemblies, but if I can't then I can't.

 

I would like to call this from an external rule, which in turn is called by one main rule (there are about 7 different assemblies I have to be able to place, while also being able to adjust a raw width and height and the associated frame members and regular parts).

 

Part of my problem is getting the newly created assembly out from the copy code. Am I correct in what I'm reading in that you can't really return variables from iLogic code? If so, that makes this a bit trickier. 

 

So, what I'm looking to do is basically this:

Start Main Rule >> Choose Compartment Configuration (each a separate rule) >> Copy Assembly and Part to New Location >> Change width and height of Skeleton Sketch >> Push Updates to Frame Generator IAM and Master Assembly >> Place Assembly into Active Assembly

 

The further end goal is to select which side these compartments go on and select the three faces to constrain to, while also using two of those faces (the raw opening) to derive width and height. 

 

Lofty goals, but if anyone has any advice, I'm all ears.

 

Thanks!

5 REPLIES 5
Message 2 of 6
JaneFan
in reply to: Anonymous

Hey @Anonymous,

 

To get all opened documents in inventor application in external rule, please use ThisApplication.Documents to get the list, then do what you need with them them next.




Jane Fan
Inventor QA Engineer
Message 3 of 6
Anonymous
in reply to: JaneFan

Edit - wrong thread

Message 4 of 6
Anonymous
in reply to: Anonymous

I am not sure if this what you are looking for.....

I have a routine I developed that will copy a subassembly from one directory to another,

do the same for all components of the assembly(it only goes one level as my subAssemblies only have one level) 

place the new subassembly in the current assembly and return the ComponentOccurrence which I then use to configure constrain the subassembly

 

piece is the name of the subassembly in the new design

compAsm is the original assembly

 

SyntaxEditor Code Snippet

        oRightJamb = placeAsm("rightJamb", "drJamb", oAsmCompDef, oTG, oMatrix)

 

 

SyntaxEditor Code Snippet

Function placeAsm(piece As String, compAsm As String, oAsmCompDef as Inventor.ComponentDefinition, _
                        oTG As Inventor.TransientGeometry, oMatrix As Inventor.Matrix)
    ' Function opens an assembly file,  saves it as a design file places the component 
    ' at the origin and returns the ComponentOccurrence

    Dim oCompDef As ComponentDefinition
    Dim path As String = ThisDoc.Path
    Dim partDir As String = path & "\parts"
    Dim designDir As String = path & "\design"
    Dim partFile As String = partDir & "\" & compAsm & ".iam"
    Dim pieceFile As String = designDir & "\" & piece & ".iam"

     ' creat copy of new jamb assembly 
    Dim oJambAsmDoc As AssemblyDocument
    Try
        oJambAsmDoc = ThisApplication.Documents.Open(partFile ,False)
    Catch
        MessageBox.Show("Could not find " & partFile, "placeAsm")
    End Try
    Try
        oJambAsmDoc.SaveAs(pieceFile , True)
        oJambAsmDoc.Close
    Catch ex As exception    
        MessageBox.Show(ex.ToString(), "placeAsm save")
        MessageBox.Show(pieceFile, "placeAsm")
    End Try

    
    ' open new assembly, create copies of parts and replace Occ in new assembly
    Try
        oJambAsmDoc = ThisApplication.Documents.Open(pieceFile ,False)
    Catch
        MessageBox.Show("Could not find " & pieceFile, "placeAsm open new piece")
    End Try
    
    Dim oPartDoc As PartDocument
    Dim newPieceFile As String
    For Each part In oJambAsmDoc.ComponentDefinition.Occurrences
    Try
        oPartDoc = ThisApplication.Documents.Open(part.Definition.Document.FullFileName ,False)
        newPieceFile = designDir & "\" & piece & part.Name & ".ipt"
        oPartDoc.SaveAs(newPieceFile, False)
        part.Replace(newPieceFile, False)
        oPartDoc.Close
        Catch ex As exception
        MessageBox.Show(ex.ToString, "opening Assembly PartDoc")
    End Try
        
    Next
    oJambAsmDoc.Save
    oJambAsmDoc.Close

    Dim oOcc = ComponentOccurence
    Try
        oOcc =  oAsmCompDef.Occurrences.Add(pieceFile, oMatrix)
    Catch ex As exception    
        MessageBox.Show(ex.ToString(), "placeAsm save")
        MessageBox.Show(pieceFile, "placeAsm")
    End Try
    oMatrix.SetTranslation(oTG.CreateVector(0,0,0))
    oOcc.Grounded = False

    Return oOcc
    
End Function      ' placeAsm

 

 

Message 5 of 6
Anonymous
in reply to: Anonymous

@Anonymous

Thank you. This is more or less what I am trying to do. I decided to develop it in VBA with plans on refactoring to an add-in. This will help as a guide should I get stuck on anything.
Message 6 of 6
Will.Ehrendreich
in reply to: Anonymous

This is really great stuff. this will help me in the future, thank you.

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report