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
Solved! Go to Solution.
Solved by tdant. Go to Solution.
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?
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.
@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.
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
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:
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
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...
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
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.
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
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
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
@Anonymous wrote:Thank you for your availability, I really appreciate it.
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.