Ilogic External Rule Copy new Named Assembly & Parts then Replace

Ilogic External Rule Copy new Named Assembly & Parts then Replace

nico
Enthusiast Enthusiast
752 Views
4 Replies
Message 1 of 5

Ilogic External Rule Copy new Named Assembly & Parts then Replace

nico
Enthusiast
Enthusiast

Ellowah

 

I'm currently trying to create an external rule in ilogic that I can call in several assembly's in the future that does the following:

 

1. Pull in excel data & update the design - Ok

2. Save this assembly under a new name - Ok

3. Save all parts that were in this assemly under a new name - Ok

4. Replace in the New Assembly these New Parts - Wrong behaviour

 

The problem I'm getting is that the New Part files are replacing the old parts in the Original Assembly instead of the new one.

My guess is that it's because the external rule is run from the Original Assembly

Even while the new assembly is opened; I've tried closing the Original Assembly but then the ilogic just crashes

 

So I'm wondering if any1 knows of a way to "Set" this "Focus" on the New Assembly so the replace only happens there.

 

Worst case I might flip the logic and make the parts first replace them and then copy the assembly but I prefer to never have the risk to overwrite the original assembly with an accidental save.

 

Kind Regards,

NVD

 

 

0 Likes
Accepted solutions (1)
753 Views
4 Replies
Replies (4)
Message 2 of 5

clutsa
Collaborator
Collaborator

Create a document variable and assign the new document to that variable. 

Dim NewDoc As Document
Dim newDocName As String = ThisDoc.Path & "\TestSaveAs.ipt"
ThisDoc.Document.SaveAs(newDocName, True)
ThisDoc.Launch(newDocName)
NewDoc = ThisApplication.Documents.ItemByName(newDocName)

NewDoc.DisplayName = "ThisWasChanged"
NewDoc.Save
If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 3 of 5

nico
Enthusiast
Enthusiast

Well I'm mainly a ducktaper of code but I don't see how that would help with "Selecting" a different assembly and run the "Replace" command

 

For visual reference see attached image for what I'm trying to achieve

"I'm not building planes btw just took something that is easily imaginable"

 

I've tried the reverse atm first creating parts then replacing all parts in the Configurator Assembly then copy that assembly and it works but I don't like it, since there's a risk of overwriting the configurator

 

Also more annoying since I would have to still manually open and close this assembly, to give a sense of scale, for this current project 316 times for 1 configurator assembly and I got 4 different ones of those todo

0 Likes
Message 4 of 5

clutsa
Collaborator
Collaborator
Accepted solution

It would look something like this

Dim NewDoc As AssemblyDocument
Dim newDocName As String = ThisDoc.Path & "\MyNewAssemblyName.iam"

ThisDoc.Document.SaveAs(newDocName, True)
ThisDoc.Launch(newDocName)
NewDoc = ThisApplication.Documents.ItemByName(newDocName)

'find the component in the newDoc and replace it
Dim partToReplace As ComponentOccurrence = NewDoc.ComponentDefinition.Occurrences.ItemByName("PartDisplayNameHere:1") 'use the parts display name
partToReplace.Replace(ThisDoc.Path & "\YourReplacementPartNameHere.ipt", False) 'use the file name (you'll probably use a variable from your excel function) 'Change to true to "replace all"

NewDoc.Save
If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 5 of 5

nico
Enthusiast
Enthusiast

Alright got it working now, cheers

NewDoc = ThisApplication.Documents.ItemByName(newDocName)

Was giving me errors before hence I was using the ThisApplication.ActiveDocument after I opened the new assembly

The reason the line above didn't work for me was a \\ in the string path

So apperently Inventor can still save and open documents with "folder\\file" but not set it as an active document

0 Likes