Showing posts with label ilogic. Show all posts
Showing posts with label ilogic. Show all posts

Friday, 16 June 2017

Turn Routes On/Off

                It has finally caught up with me and I had to stop and write a code to turn Routes On/Off.



                Nothing fancy here but I found myself doing this so many times on this last project that I decided to make an iLogic external rule for it.

                This is very simple; just a few lines to check if the occurrence name starts with "Route" then turn the part off.


------------------------------------
Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.ActiveDocument

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = oAssyDoc.ComponentDefinition

Dim oLeafOccs as ComponentOccurrencesEnumerator
oLeafOccs = oAsmCompDef.Occurrences.AllLeafOccurrences

Dim oOcc as ComponentOccurrence

'get user input as True or False
wfBoolean = InputRadioBox("Turn Routes On/Off", "On", "Off", False, "iLogic")

' Process the rule, wrapping it in a transaction so the
' entire process can be undone with a single undo operation.
Dim trans As Transaction
trans = ThisApplication.TransactionManager.StartTransaction( _
        oAssyDoc, "Routes On/Off")

    For Each oOcc In oLeafOccs
        If String.Compare(Left(oOcc.Name,5),"Route",False) = 0 Then
            'MessageBox.Show(oOcc.Name,"ilogic")
            oOcc.Visible = wfBoolean
        Else If String.Compare(Left(oOcc.Name,4),"Hose",False) = 0 Then
            oOcc.Visible = wfBoolean
        End If
    Next
'end transaction for single undo
trans.End

'upate the files
InventorVb.DocumentUpdate()
------------------------------------

Later,

ADS

Thursday, 6 April 2017

Break all cross-part sketch projections

Short and sweet: How to Break Link on cross-part projections for all occurrences in an assembly.




I have mine disabled and I don't create cross-part references. that will slow inventor to a halt, especially on large assemblies.

When you change to Modeling View inside assembly you can select and delete more than one links at a time but only if they are part of the same sketch

Here is the ilogic code used to break adaptivity. Please run this code from an Assembly, internal or external rule

----------------------------------
Dim oAsmDoc As Document 
oAsmDoc = ThisApplication.ActiveDocument

If oAsmDoc.DocumentType <> kAssemblyDocumentObject Then
    MessageBox.Show("Run this rule from an assembly!", "iLogic")
    Return
End If

i=0

For Each oDoc As Document In oAsmDoc.AllReferencedDocuments
 Try 
  If oDoc.ModelingSettings.AdaptivelyUsedInAssembly = True Then
   oDoc.ModelingSettings.AdaptivelyUsedInAssembly = False
   i += 1
  End If
 Catch
 End Try
Next

MessageBox.Show("Turned off adaptivity for " & i & " documents!", "iLogic")
----------------------------------
Please see the screencast example here:
Thanks.
ADS


photo credit: Chatsy POP.H chain (license)

Monday, 3 April 2017

Drawing Resource Transfer Wizard 2017 - Incorrect Font

Short and sweet again. No time for prelude.



If you use Drawing Resource Transfer Wizard 2017 to update title blocks for multiple drawings, text fonts would be changed incorrectly.

It is a known issue in 2017 and on Release 3 Update 1 still not working. 

Release 4 is around the corner (April release) and I was told it's fixed but till then or if we have a regression and this bug returns here is an ilogic code to automate this.

The Knowledge Base Article recommends updating manually each drawing ....hmmm... we can do better:

-------------------------------------------
Dim oDestinationDocument As DrawingDocument
oDestinationDocument = ThisApplication.ActiveDocument

Dim oSourceDocument As DrawingDocument
oSourceDocument = ThisApplication.Documents.Open("D:\ADS\CAD\TEMPLATE.idw")
 
' Get the new source title block definition.
Dim oSourceTitleBlockDef As TitleBlockDefinition
 
oSourceTitleBlockDef = oSourceDocument.TitleBlockDefinitions.Item("TITLEBLOCK_NAME")
 
' Get the new title block definition.
Dim oNewTitleBlockDef As TitleBlockDefinition
oNewTitleBlockDef = oSourceTitleBlockDef.CopyTo(oDestinationDocument,True)'true to replace existing
 
' Iterate through the sheets, replace tibleblock with the one newly added.
Dim oSheet As Sheet
For Each oSheet In oDestinationDocument.Sheets
 oSheet.Activate
 
 oSheet.TitleBlock.Delete
 Call oSheet.AddTitleBlock(oNewTitleBlockDef)
Next
-------------------------------------------
Use code Injector from here:
to update multiple files at once. There is no point to run it from the assembly (not in my case) because not all files are part of the same assembly.
Later
ADS
photo credit: PeterThoeny Space and time warp (license)

Wednesday, 21 December 2016

Component Sketches Off


I hate when people don’t clean up their models. Although not right my mind associates this to a messy person with unclean desk, car, and garage, buried in piles of unneeded stuff.



                OCD is my middle name and while I hate this side of you, I love you as well and I think maybe you weren’t taught how to do it properly.

                I suggest you never use the “Object Visibility” drop down on the View tab.

I NEVER USE IT; except to see if you’ve been cheeky and got this quick fix like a drug addict.

It’s a crapshoot and it will bite you faster than you think. Have you considered the time, effort and stress you are going to experience when using this in large assemblies.

That’s all I am going to say and I will share  a bit of iLogic code I use to clean up this mess I see regularly with sketches not being turned off.

I have another one where I turn off the visibility of workfeatures, WorkPoints, WorkAxis, WorkPlanes and I like to keep it separate from the sketch visibility because when using it with tube and pipe it will turn the routes off and I don’t want that.

Component Sketches Off

I have also wrapped the whole process as a single transaction because if I need to undo the operation I only need to do a single undo not clicking back for each sketch that is off.


Code below and in this download link

-------------------------------------------
'catch and skip errors
On Error Resume Next
'define the active assembly
Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.ActiveDocument 

'get user input as True or False
wfBoolean = InputRadioBox("Turn all Sketches On/Off", "On", "Off", False, "iLogic")

' Process the rule, wrapping it in a transaction so the 
' entire process can be undone with a single undo operation. 
Dim trans As Transaction 
trans = ThisApplication.TransactionManager.StartTransaction( _ 
        oAssyDoc, "Sketches Off")

'Check all referenced docs
Dim oDoc As Inventor.Document
For Each oDoc In oAssyDoc.AllReferencedDocuments
    'set Sketch visibility
    For Each oSketch In oDoc.ComponentDefinition.Sketches
    oSketch.Visible = wfBoolean
    Next    
    
Next

'end transaction for single undo
trans.End 

'upate the files
InventorVb.DocumentUpdate()
-------------------------------------------


Later,
ADS
photo credit: Rubina V. Jahrmarkt (license)

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)