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 Save As incl. some parts With iLogic or VBA

11 REPLIES 11
Reply
Message 1 of 12
LSA-skan
3385 Views, 11 Replies

Assembly Save As incl. some parts With iLogic or VBA

Hi

 

I have an Assembly configurated with iLogic. This assy is to be copied into new numbers for each variaty that will be made in the future. I would like the Assy and 2 specific parts to be copied, and named according to the new number.

 

Example.:

 

Master.iam

 L Master-1.ipt

 L Master-2.ipt

 L 90010.ipt

 L 90012.ipt

 

Becomes.:

 

80025.iam

 L 80025-1.ipt

 L 80025-2.ipt

 L 90010.ipt

 L 90012.ipt

 

The 900xx numbers should not be copied, as they are standard parts, which is used all around our CAD...

 

When the code is lauched, it should afterwards have the "new" assy active, hence the Save As

 

Is it possible to have iLogic or VBA do this for me..? 

 

/LSA

 

 

11 REPLIES 11
Message 2 of 12
Vladimir.Ananyev
in reply to: LSA-skan

This can be done using  FileDescriptor.ReplaceReference method.

Look at this  post please

http://adndevblog.typepad.com/manufacturing/2012/08/replace-the-file-reference-by-inventor-api.html


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 3 of 12
LSA-skan
in reply to: Vladimir.Ananyev

Hi Vladimir

 

Thanks for your reply. I checked out the site, and tried to get an idea of how i should do it, but im affraid i need a little more help to get started...

 

Here is how i think it should be done, please correct me if im wrong.. 🙂

 

first "Save copy as" on the 2 specific parts.

then "Save as" for the assy

Then replace the 2 parts in the assy with the 2 new ones that has just been created...

 

I got this from looking at the site, but im not realy sure what that the code there actually does. Is it the same as Component.Replace() in iLogic, only in VBA??

 

/LSA

Message 4 of 12
Vladimir.Ananyev
in reply to: LSA-skan

I believe iLogic function Component.Replace() is equivalent to VBA ComponentOccurrence.Replace(FileName As String, ReplaceAll As Boolean) method. 

You may find the discussion and the sample for FileDescriptor.ReplaceReference here;

http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/Assembly-Save-As-incl-some-parts-With-...

Cheers,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 5 of 12
LSA-skan
in reply to: Vladimir.Ananyev

Hehe you linked to the same thread.. 😄

 

I have been looking for a way to Simply copy a specific part in my assy. but can't seem to find a rule that does this... 

 

Something like 

ThisDoc.Document.SaveAs(NewFileNameAndExtension , True)

 

but where ThisDoc.Document is replaced with xxx.ipt

 

/LSA

Message 6 of 12
LSA-skan
in reply to: LSA-skan

Now i found a way to copy the 2 specific parts in my assy. But im now struggeling with getting the Assy copy to work The Bold Line... though it should be straight forward...?! any ideas?

 

Sub Main()
Dim Path As String = ThisDoc.Path & "\"
Dim FileChange As Boolean = False

InvDoc = ThisDoc.Document
Dim refDocs As DocumentsEnumerator = InvDoc.AllReferencedDocuments
Dim refDoc As Document
Dim PartN As String = "80061"

For Each refDoc in refDocs
If refDoc.DisplayName.EndsWith ("-2")= True Then
MessageBox.Show(refDoc.DisplayName)
NewFileName = PartN & "-2.ipt"
refDoc.SaveAs(Path & NewFileName, True)
End If
If refDoc.DisplayName.EndsWith ("-1")= True Then
MessageBox.Show(refDoc.DisplayName)
NewFileName = PartN & "-1.ipt"
refDoc.SaveAs(Path & NewFileName, True)
End If
Next


ThisDoc.Document.SaveAs(Path & PartN, False)

iLogicVb.UpdateWhenDone = True

End Sub

 

For some reason it looked at the 2 specific parts diffrently than all other parts in the assy, it didn't see the extension on them... took me some time to work that out...

 

Message 7 of 12
danvang
in reply to: LSA-skan

I looked at your code and you were just missing the file extension on the assembly saveas. Also I changed the saveas for the parts to be false. This way the parts are replaced. Test it and see how it works.

 

Dim Path As String = ThisDoc.Path & "\"

InvDoc = ThisDoc.Document
Dim refDocs As DocumentsEnumerator = InvDoc.AllReferencedDocuments
Dim refDoc As Document
Dim PartN As String = "80061"

For Each refDoc in refDocs
    'MessageBox.Show(refDoc.DisplayName)
    If refDoc.DisplayName.EndsWith("-2.ipt")= True Then
        'MessageBox.Show("found2")
        NewFileName = PartN & "-2.ipt"
        refDoc.SaveAs(Path & NewFileName, False)
    ElseIf refDoc.DisplayName.EndsWith("-1.ipt")= True Then
        'MessageBox.Show("found1")
        NewFileName = PartN & "-1.ipt"
        refDoc.SaveAs(Path & NewFileName, False)
    End If
Next


ThisDoc.Document.SaveAs(Path & PartN & ".iam", False)

iLogicVb.UpdateWhenDone = True

 

Dan

** If my reply resolves this issue, please choose "Accept as Solution" **
Dan Vang
Message 8 of 12
Tatiana_S
in reply to: danvang

I have created  a Template Assembly  

This assembly is ruled by parameters on excel and I-logic, it has parts that are standard and parts that are nonstandard that change geometry every time parameters are changed.

I’m trying to implement a programing option via I-logic or VBA that will allow the users, to enter a top level Part number and 

Automatically generate a (copy of the engineering document) of this template assembly and at the same time automatically (replace with copy the  nonstandard components) using Productstream.

 

the code that I found on the blog below from (Assembly Save As incl. some parts With iLogic or VBA)

works good outside Productstream but not integrated any idea how to integrate Ilogic and productstream to generate these files.

Thanks

 

Dim Path As String = ThisDoc.Path & "\"

 

InvDoc = ThisDoc.Document

Dim refDocs As DocumentsEnumerator = InvDoc.AllReferencedDocuments

Dim refDoc As Document

Dim PartN As String = "80061"

 

For Each refDoc in refDocs

    'MessageBox.Show(refDoc.DisplayName)

    If refDoc.DisplayName.EndsWith("-2.ipt")= True Then

        'MessageBox.Show("found2")

        NewFileName = PartN & "-2.ipt"

        refDoc.SaveAs(Path & NewFileName, False)

    ElseIf refDoc.DisplayName.EndsWith("-1.ipt")= True Then

        'MessageBox.Show("found1")

        NewFileName = PartN & "-1.ipt"

        refDoc.SaveAs(Path & NewFileName, False)

    End If

Next

 

 

ThisDoc.Document.SaveAs(Path & PartN & ".iam", False)

 

iLogicVb.UpdateWhenDone = True

 

Message 9 of 12
danvang
in reply to: Tatiana_S

No there's no way to have iLogic code connect to the Productstream (Vault Pro) do this. You will need to create a .NET addin that will connect to Productstream to do this. iLogic is only meant to work in Inventor. If what you are planning to do is copy an assembly and it's components and rename the files to new file names, any particular reason why Copy Design in Productstream is not used? Just curious.

 

Dan

** If my reply resolves this issue, please choose "Accept as Solution" **
Dan Vang
Message 10 of 12
Tatiana_S
in reply to: danvang

Thanks I appreciate your input, I’m currently working with our IT/ developers department to see if they can incorporate the option to replace with copy specific components of the assembly automatically, It will take some time they said :S We can use the option of copy design in PSP but it leaves room for error if the user forgets some of the components because is a manual process of choosing what needs to be reuse or copy. I think I can get around the issue by copy/replace the components with illogic code in silent mode so the parts would not be visible for PSP until I chose the option of Transfer Components. Tatiana_S
Message 11 of 12
Tatiana_S
in reply to: danvang

Dan

 

This code works really good for top level components, I would like to replace a subassembly and also replace a componet ipt inside that subassembly using similar code, could you please give me an example or a reference, I have been searching but have not succes finding a similar application for subassemblies and their components.

Thanks

TS

Message 12 of 12
Tatiana_S
in reply to: danvang

Dan

I wanted to reach out to you and see if you can help me with this question

I’m currently using the code of this inventor customization link and it works  good, I have some template assemblies and I’m able to automatically replace with copies some of the components or subassemblies that need changes in size.

 

It works really well replacing the parts or subassemblies from the top level template assembly, the issue I have is that first I need to replace a subassembly and once that subassembly is replaced I need to replace a part inside that subassembly.

 

So I need this code to run twice first to replace the selected child parts or subassemblies of the top assembly and then replace some parts of the subassemblies replaced during the first cycle and also to save those changes.

 

I was thinking about a code that indicate if a specific subassembly or part file name is not found in the assembly then trigger the code to run again, so far I have not found code that can trigger that option, I tried to trigger the rule the first time when the assembly opens and the second time before is saved but it doesn’t save the subassembly that contains the part just replaced during the second cycle.

I don’t want to use component.isActive because I’m not working with leves of detail in my assembly

Thanks for your help I appreciate your comments

 

Tatiana S

 

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

Post to forums  

Autodesk Design & Make Report