iLogic Rule - Convert to Sheet metal part and measure/set thickness
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I've managed to put together an iLogic rule that when run, prompts the user to select a part file to convert to sheet metal, then measure the distance between two faces to determine the thickness, that value is then set as thickness in the part. Then the next part can be selected and the process repeated.
This works quite well but when the thickness is saved it does so with lots of trailing zeroes/decimals. I've tried rounding and "format" the parameter value but it still shows up like 10,0000000. Also I had to divide the Thickness value by 10 to get the correct value, my guess is this has to do with some unit setting?
So I'd be very grateful if someone with more knowledge could take a look at the code and improve it!
We work as a subcontractor for sheet metal products and often recieve STEP files where nothing is modeled as sheet metal, with this script it will save us quite some time instead of opening up each part, measure and input the thickness manually.
Dim oADoc as AssemblyDocument
oADoc = ThisApplication.ActiveDocument
Dim comp As Object
While True
'prompt user to select an occurrence
comp = ThisApplication.CommandManager.Pick(
SelectionFilterEnum.kAssemblyLeafOccurrenceFilter,
"Select a component")
If comp Is Nothing Then
MessageBox.Show ("Selection was cancelled","ilogic")
Beep
Exit While
End If
oPartDoc = comp.Definition.Document
oFace1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllPlanarEntities,"Select Plane1")
oFace2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllPlanarEntities,"Select Plane2")
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
Try
oAsmCompDef.WorkPlanes.Item("iLogic_Proxy_Plane1").Delete
oAsmCompDef.WorkPlanes.Item("iLogic_Proxy_Plane2").Delete
Catch
'Do nothing
End Try
oPlane1 = oAsmCompDef.WorkPlanes.AddFixed(oTG.CreatePoint(0,0,0),oTG.CreateUnitVector(1,0,0),oTG.CreateUnitVector(0,1,0),False)
oPlane1.Name = "iLogic_Proxy_Plane1"
oPlane2 = oAsmCompDef.WorkPlanes.AddFixed(oTG.CreatePoint(0,0,0),oTG.CreateUnitVector(1,0,0),oTG.CreateUnitVector(0,1,0),False)
oPlane2.Name = "iLogic_Proxy_Plane2"
oAsmCompDef.Constraints.AddFlushConstraint(oPlane1,oFace1,0)
oAsmCompDef.Constraints.AddFlushConstraint(oPlane2,oFace2,0)
oDistance = Measure.MinimumDistance(oPlane1.Name,oPlane2.Name)
Try
oPartDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
'Goto EditTHK
Dim oSheetMetalCompDef As SheetMetalComponentDefinition
oSheetMetalCompDef = oPartDoc.ComponentDefinition
' Override the thickness for the document
Dim oThicknessParam As Parameter
oThicknessParam = oSheetMetalCompDef.Thickness
oThicknessParam.Value = Round(oDistance/10, 1)
Catch
MessageBox.Show("Some error occurred, make sure the selected file is not read-only or a library item.","Error")
Exit While
End Try
oAsmCompDef.WorkPlanes.Item("iLogic_Proxy_Plane1").Delete
oAsmCompDef.WorkPlanes.Item("iLogic_Proxy_Plane2").Delete
End While
I should also mention that the code I've put together are from two other threads here on the forum and then I've just made some minor changes:
https://forums.autodesk.com/t5/inventor-forum/batch-convert-regular-parts-to-sheet-metal-parts/td-p/...
https://forums.autodesk.com/t5/inventor-forum/ilogic-measure-angle-between-selected-faces/td-p/55039...
Happy for any advice!
/Fredrik