iLogic - open part and save it

iLogic - open part and save it

JoãoASilva
Advocate Advocate
5,520 Views
13 Replies
Message 1 of 14

iLogic - open part and save it

JoãoASilva
Advocate
Advocate

Hello

 

Two days ago I posted in this forum asking about saving a copy of a part from a drawing: https://forums.autodesk.com/t5/inventor-forum/save-copy-of-part-from-drawing/m-p/8230281#M709864

In that post, I was refering to a VBA code.

In the meantime, after doing a lot research, I still can't find nothing helpful.

 

I'd like to try to use iLogic do accomplish my goal, wich is:

- Have a drawing opened;

- Run rule (wich does the following):

     - Save copy of drawing  as .pdf (already found how this one is done);

     - Open the part associated to the drawing (they share the same name and folder ; found how it is done as well);

     - Save copy of part as .step (I have a rule in part to do so);

     - Close part.

 

iLogic Rule

Dim oPart As Document
Dim oPartPath As String

' Get drawing path
oPartPath = ThisDoc.PathAndFileName(False) & ".ipt"

' Open Part
oPart = ThisDoc.Launch(oPartPath)

From now on, the problem is to set the opened part as active(?), so I can run rules that are in the opened part.

I'm fairly amateur when it comes to coding, but I try to understand every line of code.

 

Thanks in advance,

João

João Silva

Mechanical Engineer

 

0 Likes
Accepted solutions (1)
5,521 Views
13 Replies
Replies (13)
Message 2 of 14

CCarreiras
Mentor
Mentor

You cant close a file from a own rule. If you want to close the part, you have to do it from other file.

Why not have all the rules in the drawing?

CCarreiras

EESignature

0 Likes
Message 3 of 14

tdant
Collaborator
Collaborator

Replace the last line of your code with this block.

' Set a reference to the target part
oPart = ThisApplication.Documents.ItemByName(oPartPath)

' Open the target part
ThisDoc.Launch(oPart)

' Save a copy of oPart as a step file
oPart.SaveAs(Replace(oPartPath, ".ipt", ".step"), True)

' Close oPart
oPart.Close

The rule that saves the part doesn't have to be inside the part itself. You can still save it from a rule in another document, which is what this does.

0 Likes
Message 4 of 14

JoãoASilva
Advocate
Advocate

@CCarreiras wrote:

You cant close a file from a own rule. If you want to close the part, you have to do it from other file.

Why not have all the rules in the drawing?


Didn't knew that.

Well, I can have all the rules in the drawings, no problem, I just want it to work. Smiley Very Happy

João Silva

Mechanical Engineer

 

0 Likes
Message 5 of 14

JoãoASilva
Advocate
Advocate

I've done as you said:

Dim oPart As Document
Dim oPartPath As String

' Get drawing path
oPartPath = ThisDoc.PathAndFileName(False) & ".ipt"

' Set a reference to the target part
oPart = ThisApplication.Documents.ItemByName(oPartPath)

' Open the target part
ThisDoc.Launch(oPart)

' Save a copy of oPart as a step file
oPart.SaveAs(Replace(oPartPath, ".ipt", ".step"), True)

' Close oPart
oPart.Close

And I'm getting an error:

Error in rule.png

Any ideas?

João Silva

Mechanical Engineer

 

0 Likes
Message 6 of 14

CCarreiras
Mentor
Mentor

Hi!

Times ago, I did something like this:

In assembly:

Go to every Assembly file

The ones which are Sheet Metal, export dxf

The ones which are parts save as step

 

Why do you need to do that from the drawing?
Só por curiosidade...

 

 

CCarreiras

EESignature

0 Likes
Message 7 of 14

JoãoASilva
Advocate
Advocate

Because the drawing is the last step before production, and we need to send the parts and drawings in various file formats, depending on the production method.

With that in mind, if i had rules for the differents production methods, I could just hit one button (macro to run rule) and it would save the files according to the production method.

João Silva

Mechanical Engineer

 

0 Likes
Message 8 of 14

CCarreiras
Mentor
Mentor

OK... i prefer to do all from the Assembly file. I think is easier to track files from the file than use other to fire rules... you have to catch all info, etc. If you use the assembly, the assembly will be the active doc.

I guess in every method there's always pros and cons.

CCarreiras

EESignature

0 Likes
Message 9 of 14

JoãoASilva
Advocate
Advocate

Easier to track, it's true.

But since we have this workflow, and we manually do the drawing for production, it's simpler for us this way.

João Silva

Mechanical Engineer

 

Message 10 of 14

tdant
Collaborator
Collaborator
Accepted solution

Sorry about that, my iLogic is a little rusty. Here's the correct, tested rule that will fit the bill:

Dim oPart As PartDocument
Dim oPartPath As String

' Get drawing path
oPartPath = ThisDoc.PathAndFileName(False) & ".ipt"

' Set a reference to the target part
oPart = ThisApplication.Documents.ItemByName(oPartPath)

' Open the target part
ThisApplication.Documents.Open(oPartPath)

' Save a copy of oPart as a step file
oPart.SaveAs(Replace(oPartPath, ".ipt", ".step"), True)

' Close oPart
oPart.Close
Message 11 of 14

JoãoASilva
Advocate
Advocate

That's great, you solved it 😉

My next step is to get everything to work with vba, so I can export multi-sheets with revision, among others.

 

Kudos to you sir.

João Silva

Mechanical Engineer

 

0 Likes
Message 12 of 14

tdant
Collaborator
Collaborator

Happy to help. If you get hung up with the VBA, give me a shout.

0 Likes
Message 13 of 14

Anonymous
Not applicable

Thank you for your availability, I really appreciate it. Smiley Happy

0 Likes
Message 14 of 14

JoãoASilva
Advocate
Advocate

@Anonymous wrote:

Thank you for your availability, I really appreciate it. Smiley Happy


I used another account to reply, my bad.

João Silva

Mechanical Engineer

 

0 Likes