Showing posts with label export. Show all posts
Showing posts with label export. Show all posts

Friday, 8 January 2016

Batch Assembly Export

Not enough time today for a proper post just a quick one. I have been working on a vb-ilogic code to identify and resolve all references. On the same process I hope to get a code for renaming the files as well.

This will of course be free and available for everybody to download from this blog but you need to stick around and check my progress because I don’t have a time frame of when that will be available.

Replacing references is working but we get into errors and limitations for special files like skeletons in Frame Generator, Tube and Pipe Route and Runs, welded assemblies, documents marked as Reference in BOM, etc. It’s a slow progress and I can’t allocate it as much time as I would like at the moment.

On a side note, there is a NDA (Non Disclosure Agreement) between me and Autodesk so I can’t say much but I was assured that the T&P list is very important for them.

Enough said on that and for today I will share a bit of code that hopefully will get your productivity up and get those manual tasks to minimum. The code needs to be run from inside an assembly and will save all parts in STEP format in a folder right next to the main assembly. I have done this code for a friend and while he is still testing you can have a preview of it (hurry up Karol).

The SaveAs option in the code can be used with any formats listed in the Save Copy As dialog but you might want to investigate the results and use the ApplicationAddIns and HasSaveCopyAsOption which will give you more control over what gets exported and some of the options in the save as dialog.

The Save As dialog can be bypassed and process the assembly as a batch

If, for example, you need to export the current drawing to PDF you can’t (shouldn’t) use the SaveAs code because it will only export the first sheet and you can’t control, colors, resolution, line weights, printing sheet range, etc. There’s more info in my previous post here.

Here’s the code, enjoy:


 'define the active document as an assembly file
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
oAsmName = ThisDoc.FileName(False) 'without extension

If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
    MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
    Exit Sub
End If
'get user input
RUsure = MessageBox.Show ( _
"This will create a STEP file for all components." _
& vbLf & " " _
& vbLf & "Are you sure you want to create STEP Drawings for all of the assembly components?" _
& vbLf & "This could take a while.", "iLogic - Batch Output STEPs ",MessageBoxButtons.YesNo)
If RUsure = vbNo Then
    Return
Else
End If
'- - - - - - - - - - - - -STEP setup - - - - - - - - - - - -
oPath = ThisDoc.Path
'get STEP target folder path
oFolder = oPath & "\" & oAsmName & " STEP Files"
'Check for the step folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If


'- - - - - - - - - - - - -Assembly - - - - - - - - - - - -
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".stp") , True)

'- - - - - - - - - - - - -Components - - - - - - - - - - - -
'look at the files referenced by the assembly
Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments
Dim oRefDoc As Document
'work the referenced models
For Each oRefDoc In oRefDocs
    Dim oCurFile As Document
    oCurFile = ThisApplication.Documents.Open(oRefDoc.FullFileName, True)
    oCurFileName = oCurFile.FullFileName
   
    'defines backslash As the subdirectory separator
    Dim strCharSep As String = System.IO.Path.DirectorySeparatorChar
   
    'find the postion of the last backslash in the path
    FNamePos = InStrRev(oCurFileName, "\", -1)  
    'get the file name with the file extension
    Name = Right(oCurFileName, Len(oCurFileName) - FNamePos)
    'get the file name (without extension)
    ShortName = Left(Name, Len(Name) - 4)

    Try
        oCurFile.SaveAs(oFolder & "\" & ShortName & (".stp") , True)
    Catch
        MessageBox.Show("Error processing " & oCurFileName, "ilogic")
    End Try
    oCurFile.Close
Next
'- - - - - - - - - - - - -
MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic")
'open the folder where the new files are saved
Shell("explorer.exe " & oFolder,vbNormalFocus)



I have tested it and save the assembly in all these other formats, including Inventor iam:

Results of exporting the assembly.
 
'- - - - - - - - - - - - -Assembly - - - - - - - - - - - - 
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".iam") , True)
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".dwg") , True)
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".bmp") , True)
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".CATProduct") , True)
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".dwf") , True)
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".dwfx") , True)
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".gif") , True)
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".igs") , True)
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".ige") , True)
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".iges") , True)
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".jpg") , True)
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".jt") , True)
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".pdf") , True)
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".png") , True)
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".x_b") , True)
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".x_t") , True)
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".g") , True)
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".neu") , True)
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".sat") , True)
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".stp") , True)
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".ste") , True)
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".step") , True)
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".stl") , True)
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".tiff") , True)
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".xgl") , True)
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".zgl") , True)


Later,
ADS


Edit 16-04-14

this is the code to append revision number at the end of the files:




Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
oAsmName = ThisDoc.FileName(False) 'without extension

If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
    MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
    Exit Sub
End If
'get user input
RUsure = MessageBox.Show ( _
"This will create a STEP file for all components." _
& vbLf & " " _
& vbLf & "Are you sure you want to create STEP Drawings for all of the assembly components?" _
& vbLf & "This could take a while.", "iLogic - Batch Output STEPs ",MessageBoxButtons.YesNo)
If RUsure = vbNo Then
    Return
Else
End If
'- - - - - - - - - - - - -STEP setup - - - - - - - - - - - -
oPath = ThisDoc.Path
'get STEP target folder path
oFolder = oPath & "\" & oAsmName & " STEP Files"

'get the document revision to use in the new filename
oRevNumAsm = iProperties.Value("Project", "Revision Number")

'Check for the step folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If


'- - - - - - - - - - - - -Assembly - - - - - - - - - - - -
ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName & "_Rev" & oRevNumAsm &(".stp") , True)

'- - - - - - - - - - - - -Components - - - - - - - - - - - -
'look at the files referenced by the assembly
Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments
Dim oRefDoc As Document
'work the referenced models
For Each oRefDoc In oRefDocs
    Dim oCurFile As Document
    oCurFile = ThisApplication.Documents.Open(oRefDoc.FullFileName, True)
    oCurFileName = oCurFile.FullFileName

   
    'defines backslash As the subdirectory separator
    Dim strCharSep As String = System.IO.Path.DirectorySeparatorChar
   
    'find the postion of the last backslash in the path
    FNamePos = InStrRev(oCurFileName, "\", -1)  
    'get the file name with the file extension
    Name = Right(oCurFileName, Len(oCurFileName) - FNamePos)
    'get the file name (without extension)
    ShortName = Left(Name, Len(Name) - 4)
    oRevDoc = iProperties.Value(Name, "Project", "Revision Number")


    Try
        oCurFile.SaveAs(oFolder & "\" & ShortName & "_Rev" & oRevDoc & (".stp") , True)
    Catch
        MessageBox.Show("Error processing " & oCurFileName, "ilogic")
    End Try
    oCurFile.Close
Next
'- - - - - - - - - - - - -
MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic")
'open the folder where the new files are saved
Shell("explorer.exe " & oFolder,vbNormalFocus)



Friday, 27 November 2015

Improving Drawing Appearance

                One thing you have to admit: Inventor drawings can look pretty dull compared with AutoCAD and other packages. Even if you don’t customize your templates and you use the default ones that come with AutoCAD you will get pretty decent looking, good contrasting, and visual appealing drawings.
Choosing the right color for your layers is a difficult task
                Habit and taking things for granted had stopped me from customizing Inventor templates but I am in the process of changing this and improve the aspect of my drawings. When I was editing “Mastering Inventor 2016” there were a couple of files there created by my predecessors with different colors and layers and they looked really good. Slapped the back of my head for not trying it earlier and made a note to start this as soon as.

                There are some things I need to mention before asking you to try this out.

You need to think about what happens to your drawings once finished! Do you export them to PDF, DXF, or DWG? Then you might want to check how they will look with all the changed layers. Some colors will look good on the white/yellow Inventor background but will not be visible on the black background of AutoCAD. While you can print in black and force exports to all black, I would still test this out and discuss it with your colleagues to see if they can remember to tick this option every time or you need to customize their settings and implement some procedures.


Print all colors as black.
Save pdf: all colors as black
You will have to avoid some colors, and no matter how much you like them, some colors you can’t use! I am talking about Cyan, Magenta and Red and that’s because they are used already and they will clutter your drawing making it hard to edit.

Cyan is used to show unattached, orphaned end points, center points, centerlines, etc. kind of stuff and you want it to stick out so you can delete them or drag them to a new attachment location.

Magenta is used to show orphaned dimensions and annotations and you want them sticking out as well and just like above you will want to delete them or attach them to a new location.

                Red is used to pre-highlight geometry like when you hover your mouse over various geometry and elements of the drawing. You will also like to spare this color so that any drawing markup (usually in red) is visible and stands out the drawing, be that printed, pdf, dwf or just plain images.
Some colors you should not use
                Sky’s the limit, go creative and use your wild imagination but test it out for a couple of days. I would not use very bright or high contrasting colors because they tend to wear you down and make you eyes tired.

                With the drawing open click on Styles Editor on the Manage tab and head over to layers to change the display. If you can’t decide open an AutoCAD template like ISO or ANSI and use those colors as a starting point.
Style Manager dialog.

                I only have one recommendation and that is to use grey (any shade) for Hidden and Hidden Narrow layers. It will make it look like wireframe in model making the visible edges stand out.
Use grey for Hidden edges (click on the image to enlarge).
                Hope you fight your habits hard; it’s the only way forward.

                Later,
                ADS




photo credit: photo (license)

Wednesday, 15 October 2014

Sheet metal imports

Let me drop a couple of words on getting flat patters from imported components. I've seen a lot of imported parts lately created in other cad packages (Catia in this case) with punches that Inventor has problem creating flat pattern for.

The secret here is to use delete face with heal on and delete the inside of the punch first and only afterwards the outside faces of the punch in a separate delete operation. You can select inside faces of all punches for your first delete face operation.






If your vendor exported an assembly with one part, Inventor will imported it as multi-body part with one body and it will complain that it can't be converted to sheet metal.

In this case you can export it again to a neutral file format and import that back or you can use derive to get it all as one body.

I have a test model for you made with Inventor 2014 where you can try these out.

When you try and convert to sheet metal you will see that inventor complains about having multiple bodies so we need to derive it into a single body.

1. Open a new part.

2. Go to 3d model / create/ derive and browse to our file : 141017 Sheet metal imports.ipt

3. In the derived part dialog, expand solid bodies, and unmark Body.1 (you only need to have Body.13)

4. On the derived style select single solid body and click ok.





Even though we have only one body it seems that the round inserts at the end of the arms are modeled in so we need to remove them to a constant thickness part.

5. Extrude-cut the sheet metal nuts (round inserts)


6. Select the inside faces of the punches, one at a time or all at once. Start the delete face operation and after marking heal option click ok. You should have something as in the images bellow.





 7. Repeat the operation again for the outside faces of the punches. The end result should be like this:





 8. Verify the thickness and change it accordingly in the sheet metal options.

9. Use flat pattern. You might need to select one face (inside face) before flat patterning if it doesn't unfold. You might also need to delete the existing flat pattern if any to get it to compute.



And of course a video.



ADS