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: 

Assembly Manipulation

1 REPLY 1
Reply
Message 1 of 2
Anonymous
130 Views, 1 Reply

Assembly Manipulation

I am adding parts in an assembly. I have a routine that takes the new part
(automatically assigned Part6) and saves it to the folder as the next
progressive part number (99999-0103 for example). This logic is complete
and works great.

The problem is, I need to get rid of Part6, and I need to replace it with
99999-0103. Part6 has not been saved yet, but was SaveAs(ed) 99999-0103.
Remember, I am working in the assembly (not a part) document.

I've looked at the API examples for assemblies, but don't see a good fit for
this application.

Partial Code pasted below, and thanks in advance for the help!
--------------

' If oPartDoc2.FullFileName = "" Then
Call oPartDoc2.SaveAs(JobPath & PN & ".ipt", False)
' ElseIf Right(Left(oPartDoc2.FullFileName, (len3 - 5)), 4) = "Part"
Then
' If TypeOf ThisApplication.ActiveEditObject Is Sketch Then
' Dim oSketch As Sketch
' Set oSketch = ThisApplication.ActiveEditObject
' oSketch.ExitEdit
' End If

' Call oPartDoc2.SaveAs(JobPath & PN & ".ipt", False)
' End If

' Add newly saved part to the assembly
If ThisApplication.ActiveDocumentType = kAssemblyDocumentObject Then
' Need to close and remove the current component
Call oPartDoc2.Close(False)

Dim oAsmCompDef As AssemblyComponentDefinition
Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry

Dim oMatrix As Matrix
Set oMatrix = oTG.CreateMatrix

Call oMatrix.SetToRotation(3.14159265358979 / 4, oTG.CreateVector(0,
0, 1), oTG.CreatePoint(0, 0, 0))

Call oMatrix.SetTranslation(oTG.CreateVector(3, 2, 1))

Dim oOcc As ComponentOccurrence
Debug.Print JobPath & PN & ".ipt"
Set oOcc = oAsmCompDef.Occurrences.Add(JobPath & PN & ".ipt",
oMatrix)

End If
1 REPLY 1
Message 2 of 2
Anonymous
in reply to: Anonymous

In response to my last question, I
have determined that it is not necessary to insert a component.  The Part6
is updated to 99999-0103 when I exit the assembly and re-open.  I am asked
if I would like to do an update.

 

The question is, can I perform this
update automatically?  In the code below, these two lines are what I
question. 


size=2>        Call
oPartDoc2.Close(False)
       
ThisApplication.ActiveDocument.Update

 

 

Latest code posted below... 
Update incorporated.  Thanks in advance for the help...

 

-----------------

 

    ' If
oPartDoc2.FullFileName = "" Then
       
Call oPartDoc2.SaveAs(JobPath & PN & ".ipt",
False)
    ' ElseIf Right(Left(oPartDoc2.FullFileName, (len3 -
5)), 4) = "Part" Then
    '     If TypeOf
ThisApplication.ActiveEditObject Is Sketch Then
   
'         Dim oSketch As
Sketch
    '        
Set oSketch = ThisApplication.ActiveEditObject
   
'        
oSketch.ExitEdit
    '     End
If
       
   
'     Call oPartDoc2.SaveAs(JobPath & PN & ".ipt",
False)
    ' End If
   

   
    ' Add newly saved part to the
assembly
    If ThisApplication.ActiveDocumentType =
kAssemblyDocumentObject Then
        '
Need to close and remove the current
component
        Call
oPartDoc2.Close(False)
       
ThisApplication.ActiveDocument.Update

                               

        ' The Code Below is for adding
components.  We only need to update in this
case...
        '
-----------------------------------------------------------------------------------------------------------------------------------------------------
       
' Dim oAsmCompDef As
AssemblyComponentDefinition
        ' Set
oAsmCompDef =
ThisApplication.ActiveDocument.ComponentDefinition
       

        ' Dim oTG As
TransientGeometry
        ' Set oTG =
ThisApplication.TransientGeometry
       

        ' Dim oMatrix As
Matrix
        ' Set oMatrix =
oTG.CreateMatrix
       

        ' Call
oMatrix.SetToRotation(3.14159265358979 / 4, oTG.CreateVector(0, 0, 1),
oTG.CreatePoint(0, 0, 0))
       

        ' Call
oMatrix.SetTranslation(oTG.CreateVector(3, 2,
1))
       

        ' Dim oOcc As
ComponentOccurrence
        ' Debug.Print
JobPath & PN & ".ipt"
        '
Set oOcc = oAsmCompDef.Occurrences.Add(JobPath & PN & ".ipt",
oMatrix)
       
   
End If

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

Post to forums  

Autodesk Design & Make Report