Issue:

![]() |
An example text file list |
![]() |
The list presented to the user in an input list box. |
![]() |
The input box presented to the user to set the quantity. |
![]() |
The virtual parts added to the assembly. |
![]() |
Adjusting the quantity. |
![]() |
The iLogic rule deletes the original 18 occurrences and just adds back the number specified. |
![]() |
An example XLS file list with iProperty information. |
'reset List B list to default
MultiValue.SetList("List_B", 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
'reset List C list to default
MultiValue.SetList("List_C", 2,4,6,8,10,12,14,16)
DimB_ListAsNewArrayList
B_List=MultiValue.List("List_B")
DimC_ListAsNewArrayList
C_List=MultiValue.List("List_C")
DimTemp_ListAsNewArrayList
Temp_List.Clear
ForEachoIteminB_List
IfList_A>=oItemThen
Temp_List.Add(oItem)
EndIf
Next
MultiValue.List("List_B")=Temp_List
Temp_List.Clear
ForEachoIteminC_List
IfList_A>=oItemThen
Temp_List.Add(oItem)
EndIf
Next
MultiValue.List("List_C")=Temp_List
Issue:
Solution:
Here is a quick routine written for iLogic using the API to do this. This employs the CommandManager's Pick function to allow you to select individual dimensions and set the tolerance.
Thank you! to Ron Moore, for the question/post idea.
oMsg = "Select sketch dimensions to apply default tolerance (Press Esc to continue)"
WhileTrue
DimoDimensionAsDimensionConstraint
oDimension= ThisApplication.CommandManager.Pick(
SelectionFilterEnum.kSketchDimConstraintFilter, oMsg)
' If nothing gets selected then we're done
IfIsNothing(oDimension) ThenExitWhile
oDimension.Parameter.Tolerance.SetToSymmetric(0.05)
EndWhile
Issue:
You're writing a bit of code that might be used in Inventor documents of varying unit types. For instance maybe this code is sometimes used in inch based parts, other times it's used in millimeter based parts, and sometime centimeter based parts. Or maybe the part has some dimensions entered in inches and some entered in millimeters. In any case you want your code to handle all of this.
Solution:
Below is a quick example that you can use to do the units detection and conversion in your code.
Here is the basic function. It uses the document's length units and centimeters to determine the conversion factor, and displays this in a message box to return the conversion factor.
DimoUOMAsUnitsOfMeasure
oUOM = ThisDoc.Document.UnitsOfMeasure
oLenUnits = oUOM.GetStringFromType(UnitsTypeEnum.kDefaultDisplayLengthUnits)
oInvUnits = UnitsTypeEnum.kCentimeterLengthUnits
oInvUnitString = oUOM.GetStringFromType(oInvUnits)
oConversion = oUOM.ConvertUnits(1, oUOM.LengthUnits, oInvUnits)
MsgBox("Document Units = "& oLenUnits& vbLf& _
"Inventor Internal Units = "& oInvUnitString& vbLf& _
"Conversion factor = "& oConversion, , "Inventor")
Here a sketch dimension/parameter named length is set to 70 mm, even though the part file is using Inches. And because our code is using the API to get the parameter value, we know that it's going to be returned in centimeters.
Without the conversion factor, the code returns 7, which is the value in Inventor's internal units of centimeters.
So we use the UnitsOfMeasure.ConvertUnits function to handle all of this and return the expected value in the document units.
With the conversion code, it returns 2.756, which is the value in inches.
Here's the working example:
DimoUOMAsUnitsOfMeasure
oUOM = ThisDoc.Document.UnitsOfMeasure
oConversion = oUOM.ConvertUnits(1, oUOM.LengthUnits, _
UnitsTypeEnum.kCentimeterLengthUnits)
oMsg = "Select a sketch dimension(Press Esc to continue)"
WhileTrue
DimoDimensionAsDimensionConstraint
oDimension = ThisApplication.CommandManager.Pick(
SelectionFilterEnum.kSketchDimConstraintFilter, oMsg)
' If nothing gets selected then we're done
IfIsNothing(oDimension) ThenExitWhile
oParam = oDimension.Parameter
oParamVal = Round(oParam.Value() / oConversion, 3)
MsgBox(oParamVal,,"Inventor")
EndWhile
Issue:
You have a parts list that has a challenging sort criteria, due to needing to sort for values that might or might not exist in the same column.
In the example above we want to sort the description column based on all items with a mark number (MK) value, and then sort those without a mark number alphabetically.
Solution:
Although we can't accomplish this out of the box, here is a code example to this that using iLogic and some API calls.
sSortColumnName = "KEYWORDS"
' Set a reference to the drawing document.
' This assumes a drawing document is active.
DimoDrawDocAsDrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
' Set a reference to the first parts list on the active sheet.
DimoPartsListAsPartsList
Try
oPartsList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
Catch
Return'exit rule
EndTry
DimoADocAsAssemblyDocument
oADoc = oPartsList.ReferencedDocumentDescriptor.ReferencedDocument
DimoPropSetAsPropertySet
oPropSet = oADoc.PropertySets.Item("Inventor Summary Information")
'add temporary column to the parts list
oID = oPropSet.Item(sSortColumnName).PropId
Try
oPartsList.PartsListColumns.Add _
(PropertyTypeEnum.kFileProperty, oPropSet.InternalName, oID)
Catch
EndTry
' Iterate through the contents of the parts list.
DimiAsLong
Fori = 1 TooPartsList.PartsListRows.Count
'get the Description value
oCell = oPartsList.PartsListRows.Item(i).Item("DESCRIPTION")
'split the string at the comma
'expecting a string like:
' Bracket, MK B-114
sArray = Split(oCell.Value, ",")
sType = sArray(0)
Try
sMK = sArray(1)
Catch'error when no comma in string
sMK = ""
EndTry
'get the temp column cell
oTempColumnCell = oPartsList.PartsListRows.Item(i).Item(sSortColumnName)
'write to temp column
IfsMK.Contains("MK") Then
'strip off the MK
sMK = Replace(sMK, "MK ", "")
oTempColumnCell.Value = sMK
Else
oTempColumnCell.Value = sType
EndIf
Next
'sort and renumber
oPartsList.Sort(sSortColumnName)
oPartsList.Renumber
'remove temp column
oPartsList.PartsListColumns(sSortColumnName).remove
Solution:
You can use this example iLogic rule to traverse the assembly (and subassemblies) to turn off all work features and sketches.
SubMain
DimoDocAsAssemblyDocument = ThisApplication.ActiveDocument
DimoOccsAsComponentOccurrences = oDoc.ComponentDefinition.Occurrences
DimsNameAsString
sName = oDoc.DisplayName
'set vis in the top level
CallSetVis(oDoc, sName)
CallTraverseAssembly(oOccs)
EndSub
SubTraverseAssembly(oOccsAsComponentOccurrences)
DimoOccAsComponentOccurrence
ForEachoOccInoOccs
DimoDocAsDocument
oDoc = oOcc.Definition.Document
DimsNameAsString
sName = oOcc.Name
'set vis in the component
CallSetVis(oOcc.Definition.Document, sName)
'if sub assembly step into it's Occurrences collection
IfoOcc.DefinitionDocumentType = _
DocumentTypeEnum.kAssemblyDocumentObjectThen
Logger.Info("Stepping into: "& sName)
oSubOccs = oDoc.ComponentDefinition.Occurrences
CallTraverseAssembly(oSubOccs)
EndIf
Next
EndSub
SubSetVis(oDocAsDocument, sNameAsString)
DimoDefAsComponentDefinition
oDef = oDoc.ComponentDefinition
ForEachoItemInoDef.Workplanes
Try
oItem.visible = False
Catch
Logger.Info("Could not set work plane vis for: "& sName)
EndTry
Next
ForEachoItemInoDef.WorkAxes
Try
oItem.visible = False
Catch
Logger.Info("Could not set work axis vis for: "& sName)
EndTry
Next
ForEachoItemInoDef.WorkPoints
Try
oItem.visible = False
Catch
Logger.Info("Could not set work point vis for: "& sName)
EndTry
Next
ForEachoItemInoDef.Sketches
Try
oItem.visible = False
Catch
Logger.Info("Could not set sketch vis for: "& sName)
EndTry
Next
EndSub
Solution:
Here is a quick iLogic rule to do this.
oBorderName = "My Border"
oTitleBlockName = "My Title Block"
oSymbolName = "My Symbol"
oResourceFile = "C:\Temp\MyDrawingResourceFile.idw"
'open source file
DimoSourceFileAsDrawingDocument
oSourceFile = ThisApplication.Documents.Open(oResourceFile, False)
DimoDocAsDrawingDocument
oDoc = ThisDoc.Document
'copy the resources from the source file, replace existing
oSourceFile.BorderDefinitions.Item(oBorderName).CopyTo(oDoc, True)
oSourceFile.TitleBlockDefinitions.Item(oTitleBlockName).CopyTo(oDoc, True)
oSourceFile.SketchedSymbolDefinitions.Item(oSymbolName).CopyTo(oDoc, True)
'close source file
oSourceFile.Close(True)
Issue:
You would like to set the view scale of your drawing views using the predefined scale list as found at Manage tab > Styles Editor button > Standard > Standard name> General tab > Preset Values> Scale
Solution:
Here is a quick bit of code to get this list and set the scale based on the scale selected from the input list box.
( Thank you! to Zach B. for the idea for the rule)
DimoDocAsDrawingDocument = ThisApplication.ActiveDocument
DimoStyleManagerAsDrawingStylesManager = oDoc.StylesManager
DimoActiveStandardAsDrawingStandardStyle
oActiveStandard = oDoc.StylesManager.ActiveStandardStyle
DimoListAsNewList(OfString)
ForEachoItemInoActiveStandard.PresetScales
oList.Add(oItem)
Next
DimoViewAsDrawingView
oCurrentScale = oDoc.ActiveSheet.DrawingViews.Item(1).ScaleString
DimoScaleAsString = InputListBox("Select a scale", _
oList, oCurrentScale, "iLogic", "Standard Scale List")
IfString.IsNullOrWhiteSpace(oScale) ThenExitSub
ForEachoViewInoDoc.ActiveSheet.DrawingViews
IfoView.ScaleFromBase = FalseThen
oView.ScaleString = oScale
EndIf
Next
Planning to attend Autodesk University 2023 in November?
If so join me on Tuesday, November 14th as I present a practical guide to transitioning from iLogic to Inventor add-ins.
Hope to see you there!
MFG601910 | Bridging the Gap Between iLogic Automation and Inventor Add-Ins
Tuesday, Nov 1410:30 AM - 12:00 PM PST
Issue:
You'd like to be able to open a component drawing by selecting a balloon from an assembly drawing.
Solution:
Here is an iLogic rule that uses a bit of API code to do this.
DimoDocAsDrawingDocument = ThisApplication.ActiveDocumentWhileTrue'select BalloonDimoBalloonAsBalloon = NothingoBalloon = ThisApplication.CommandManager.Pick _ (SelectionFilterEnum.kDrawingBalloonFilter, _ "Select a balloon to open it's drawing. "& " (press ESC To Exit selection)") IfIsNothing(oBalloon) ThenExitWhileDimoLeaderAsLeaderIfoBalloonIsNotNothingThenoLeader = oBalloon.LeaderDimoLeaderNodeAsLeaderNode = oLeader.AllNodes(oLeader.AllNodes.Count) DimoIntentAsGeometryIntent = oLeaderNode.AttachedEntityDimoCurveAsDrawingCurve = oIntent.GeometryDimoOccAsComponentOccurrence = oCurve.ModelGeometry.ContainingOccurrenceDimoRefDocAsDocument = oOcc.Definition.DocumentDimoFilePathAsString = oRefDoc.FullFileName() DimoDrawingFilePathAsString = Left(oFilePath, Len(oFilePath) -3) & "idw"TryoDrawDoc = ThisApplication.Documents.Open(oDrawingFilePath, True) ExitWhileCatchMsgBox("Could not open "& oDrawingFilePath, , "iLogic") EndTryEndWhile