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 - open part and save it

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
JoãoASilva
4963 Views, 13 Replies

iLogic - open part and save it

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

 

If what I said solved your problem, or answered your question, please use the ACCEPT AS SOLUTION or KUDOS buttons.

Or if it helped you, please hit "LIKE" 

 

Inventor Professional 2023.3, Build 359

13 REPLIES 13
Message 2 of 14
CCarreiras
in reply to: JoãoASilva

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

Message 3 of 14
tdant
in reply to: JoãoASilva

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.

Message 4 of 14
JoãoASilva
in reply to: CCarreiras


@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

 

If what I said solved your problem, or answered your question, please use the ACCEPT AS SOLUTION or KUDOS buttons.

Or if it helped you, please hit "LIKE" 

 

Inventor Professional 2023.3, Build 359

Message 5 of 14
JoãoASilva
in reply to: tdant

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

 

If what I said solved your problem, or answered your question, please use the ACCEPT AS SOLUTION or KUDOS buttons.

Or if it helped you, please hit "LIKE" 

 

Inventor Professional 2023.3, Build 359

Message 6 of 14
CCarreiras
in reply to: JoãoASilva

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

Message 7 of 14
JoãoASilva
in reply to: CCarreiras

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

 

If what I said solved your problem, or answered your question, please use the ACCEPT AS SOLUTION or KUDOS buttons.

Or if it helped you, please hit "LIKE" 

 

Inventor Professional 2023.3, Build 359

Message 8 of 14
CCarreiras
in reply to: JoãoASilva

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

Message 9 of 14
JoãoASilva
in reply to: CCarreiras

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

 

If what I said solved your problem, or answered your question, please use the ACCEPT AS SOLUTION or KUDOS buttons.

Or if it helped you, please hit "LIKE" 

 

Inventor Professional 2023.3, Build 359

Message 10 of 14
tdant
in reply to: JoãoASilva

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
in reply to: tdant

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

 

If what I said solved your problem, or answered your question, please use the ACCEPT AS SOLUTION or KUDOS buttons.

Or if it helped you, please hit "LIKE" 

 

Inventor Professional 2023.3, Build 359

Message 12 of 14
tdant
in reply to: JoãoASilva

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

Message 13 of 14
Anonymous
in reply to: tdant

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

Message 14 of 14
JoãoASilva
in reply to: Anonymous


@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

 

If what I said solved your problem, or answered your question, please use the ACCEPT AS SOLUTION or KUDOS buttons.

Or if it helped you, please hit "LIKE" 

 

Inventor Professional 2023.3, Build 359

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

Post to forums  

Autodesk Design & Make Report