Save copy of part from drawing

Save copy of part from drawing

JoãoASilva
Advocate Advocate
490 Views
5 Replies
Message 1 of 6

Save copy of part from drawing

JoãoASilva
Advocate
Advocate

Hello everyone!

 

Where I work we need to save files in various formats to send to manufacturers, and sometimes it's a tedious process and can lead to missing one or two files.

 

This is what we do:

- We create parts, make an assembly of those parts and then, if everything is okay, we go for the drawings of each part;

- If the part is a sheet metal: we need to save a copy as .pdf and .dxf of the drawing (wich I got set to a macro using iLogic); if it is a normal part, we need a .pdf of the drawing and a .step of the part.

 

This is what I want:

- Is it possible to have a way to save a copy of the part as .step and its drawing as .pdf, from within the drawing, using a macro?

 

This way, I could finish the drawing, hit the button (macro), and I would have both files saved.

 

Many thanks!

João Silva

Mechanical Engineer

 

0 Likes
491 Views
5 Replies
Replies (5)
Message 2 of 6

mcgyvr
Consultant
Consultant

@JoãoASilva wrote:

Hello everyone!

 

Where I work we need to save files in various formats to send to manufacturers, and sometimes it's a tedious process and can lead to missing one or two files.

 

This is what we do:

- We create parts, make an assembly of those parts and then, if everything is okay, we go for the drawings of each part;

- If the part is a sheet metal: we need to save a copy as .pdf and .dxf of the drawing (wich I got set to a macro using iLogic); if it is a normal part, we need a .pdf of the drawing and a .step of the part.

 

This is what I want:

- Is it possible to have a way to save a copy of the part as .step and its drawing as .pdf, from within the drawing, using a macro?

 

This way, I could finish the drawing, hit the button (macro), and I would have both files saved.

 

Many thanks!


Yes thats possible with ilogic..

Please post your complete ilogic code that you are currently using so it can be edited as you want..

 

Like in your other post the locations of where you want these files is something that needs to be known before the code can be written completely..

So please state where these files will be saved..

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes
Message 3 of 6

JoãoASilva
Advocate
Advocate

@mcgyvr wrote:


Yes thats possible with ilogic..

Please post your complete ilogic code that you are currently using so it can be edited as you want..

 

Like in your other post the locations of where you want these files is something that needs to be known before the code can be written completely..

So please state where these files will be saved..

 


I'm using rules in iLogic to do what I want within the document, and then I have a template macro to run each rule.

The problem is that, for this problem, I dont have an iLogic code.

But I was thinking something like this (please note that I'm really new to coding, so I can be taking the wrong thinking path):

 

- Get file name of model in drawing;

- Locate path of file name;

- Launch Document;

- Save copy as .step (I know this line of code);

- Close document.

 

- - - - - - -

The part is created in a folder relative to the project we are working on, and that doesn't change.

The drawing goes in the same folder as the part, so if we have the drawing path, we also have the part path.

 

 

João Silva

Mechanical Engineer

 

0 Likes
Message 4 of 6

mcgyvr
Consultant
Consultant

@JoãoASilva wrote:

The part is created in a folder relative to the project we are working on, and that doesn't change.

The drawing goes in the same folder as the part, so if we have the drawing path, we also have the part path.

 

 


The reason I asked for your existing ilogic rule is so I could get the answers to these questions below... 

Where does the pdf file get saved..same folder as part/drawing? And does anything get appended to its name (like revision?)..

Where does the dxf file get saved..same folder as part/drawingAnd does anything get appended to its name (like revision?)..

Where does the step file get saved..same folder as part/drawing? And does anything get appended to its name (like revision?)..

 

Also

By macro do you mean ilogic trigger? or are you actually using a vb macro?

Would you be fine if it just made the files on the "before save" event trigger? (so you press save and it runs this ilogic rule to create all the associated files then saves the drawing)

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes
Message 5 of 6

JoãoASilva
Advocate
Advocate

The reason I asked for your existing ilogic rule is so I could get the answers to these questions below... 

Where does the pdf file get saved..same folder as part/drawing? In our network, same folder for parts and drawings.  And does anything get appended to its name (like revision?).. Yes, but they always share the same name.

Where does the dxf file get saved..same folder as part/drawing? Same as above. And does anything get appended to its name (like revision?).. Same as above.

Where does the step file get saved..same folder as part/drawing? Same as above. And does anything get appended to its name (like revision?).. Same as above.

 

Also

By macro do you mean ilogic trigger? I really mean a macro. or are you actually using a vb macro? Yes.

Would you be fine if it just made the files on the "before save" event trigger? (so you press save and it runs this ilogic rule to create all the associated files then saves the drawing) I would much prefer not to use an event trigger as such, for a simple reason: I am constantly saving and discarding obsolete parts for new ones, and if it saved a copy as a diferent file format everytime, our network would be a total chaos.

 

Regarding the code, I did some progress:

 

' Find the drawing for the specified part of assembly.
Private Function FindDrawingFile(PartOrAssemblyDoc As Document)
    Dim fullFilename As String
    fullFilename = PartOrAssemblyDoc.fullFilename
    
    ' Extract the path from the full filename.
    Dim path As String
    path = Left$(fullFilename, InStrRev(fullFilename, "\"))
    
    ' Extract the filename from the full filename.
    Dim filename As String
    filename = Right$(fullFilename, Len(fullFilename) - InStrRev(fullFilename, "\"))
    
    ' Replace the extension with "dwg"
    filename = Left$(filename, InStrRev(filename, ".")) & "dwg"
    
    ' Find if the drawing exists.
    Dim drawingFilename As String
    drawingFilename = ThisApplication.DesignProjectManager.ResolveFile(path, filename)
    
    ' Check the result.
    If drawingFilename = "" Then
        ' Try again with idw extension.
        filename = Left$(filename, InStrRev(filename, ".")) & "idw"
        
        ' Find if the drawing exists.
        drawingFilename = ThisApplication.DesignProjectManager.ResolveFile(path, filename)
    
        ' Return the result.
        If drawingFilename <> "" Then
            FindDrawingFile = drawingFilename
        Else
            FindDrawingFile = ""
        End If
    Else
        ' Return the result.
        FindDrawingFile = drawingFilename
    End If
    
    ' Open Drawing
    Dim oDoc As Document
    Set oDoc = ThisApplication.Documents.Open(drawingFilename, True)

    ' From here on out I don't know
    drawingFilename = ThisApplication.ActiveDocument '?
    
    
    
End Function

I already have a Rule for my drawings that saves the drawing as .pdf and .dxf

 

 

The next step would be to set the drawing as the active document and make it run its Rule.

 

In the end, if all goes well, I can change the code to open the part from the drawing, and make it run a rule to save a copy of the part as .step, without having to do it manually.

João Silva

Mechanical Engineer

 

0 Likes
Message 6 of 6

JoãoASilva
Advocate
Advocate

This is the VBA code I have for running the iLogic Rule:

Public Sub Chapa_Quinada_PDF_DXF()

Dim iLogicAuto As Object
Set iLogicAuto = GetiLogicAddin(ThisApplication)
If (iLogicAuto Is Nothing) Then Exit Sub

Dim doc As Document
Set doc = ThisApplication.ActiveDocument

Dim ruleName As String
ruleName = "Save As PDF & DXF"
Dim rule As Object
Set rule = iLogicAuto.GetRule(doc, "Save As PDF & DXF")
If (rule Is Nothing) Then
  Call MsgBox("No rule named " & ruleName & " was found in the document.")
  Exit Sub
End If

Dim i As Integer
i = iLogicAuto.RunRuleDirect(rule)

End Sub


Function GetiLogicAddin(oApplication As Inventor.Application) As Object
Set addIns = oApplication.ApplicationAddIns

Dim addIn As ApplicationAddIn
On Error GoTo NotFound
Set addIn = oApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")

If (addIn Is Nothing) Then Exit Function

addIn.Activate
Set GetiLogicAddin = addIn.Automation
Exit Function
NotFound:

End Function

And this is the rule I have in the drawing to run from the macro above:

ThisDoc.Document.SaveAs(ThisDoc.ChangeExtension(".pdf"), True)
ThisDoc.Document.SaveAs(ThisDoc.ChangeExtension(".dxf"), True)

MessageBox.Show("2 - Corte Laser", "Saved As:")

João Silva

Mechanical Engineer

 

0 Likes