iLogic Rule - Convert to Sheet metal part and measure/set thickness

iLogic Rule - Convert to Sheet metal part and measure/set thickness

Wowbagger2
Enthusiast Enthusiast
2,791 Views
5 Replies
Message 1 of 6

iLogic Rule - Convert to Sheet metal part and measure/set thickness

Wowbagger2
Enthusiast
Enthusiast

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

0 Likes
2,792 Views
5 Replies
Replies (5)
Message 2 of 6

MechMachineMan
Advisor
Advisor

1. Yes the 10 factor would be due to unit conversions assuming you are working in 'mm', as inventor's database units are in 'cm' so it returns the value in cm.

2. Why does it matter that it has trailing zeros? It shouldn't show up anywhere...


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 6

Wowbagger2
Enthusiast
Enthusiast

1. Ok, that's what I thought, is there anyway to define the units as mm so I dont need to divide it?

2. We use the Thickness value for our BOM's so that could be a problem, although the script to put the Thickness value in the iProperties could round it off.

  

I admit both of these problems are quite minor but out of interest to learn more ilogic I'd still like to improve the script if possible.

0 Likes
Message 4 of 6

MechMachineMan
Advisor
Advisor

1. No. The return values from the API calls are in database units, so you have to convert it one way or another.

 

2. I hope you are making it an iProperty properly by using the "Exposed as property" setting. Within this, you can remove the trailing zeros by setting the "Custom Property Format" to exclude trailing zeroes. See my signature for links for resources that will help you with finding solutions for this. ie; namely the programming help and other posts in the forums.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 5 of 6

Anonymous
Not applicable

buonasera a tutti, ho provato questa regola ilogic, e funziona solo se i file hanno la regola lamiera non fleggata, come nel mio caso che importo degli step, nel momento della conversione  la regola da errore

mcremamarco_2-1616605438813.png

in quanto da parte a lamiera, si trova la regola lamiera fleggata

mcremamarco_1-1616605402615.png

e possibile risolvere il problema????

 

Grazie mille

 

0 Likes
Message 6 of 6

A.Acheson
Mentor
Mentor

@Anonymous 


Italian to English translation

good evening everyone, I tried this ilogic rule, and it only works if the files have the sheet metal rule not flegged, as in my case what amount of steps, at the time of conversion the error rule

 

The rule above sets the thickness of a  default sheetmetal style each time and does not follow the sheetmetal styles. 

In order to follow the sheetmetal style you need to activate the style by name using 

SheetMetal.SetActiveStyle(“styleName”)

A sample could be

 

If Thickness = “6” Then
SheetMetal
.SetActiveStyle(“SteelPlate-6”)
End If

https://knowledge.autodesk.com/support/inventor-products/learn-explore/caas/CloudHelp/cloudhelp/2014/ENU/Inventor/files/GUID-42F118D3-1022-4A78-8495-BFD13A450EED-htm.html 

If do not want to follow the style, you can switch off the follow style check box, how I do not know😢

Do you want the style on or off?

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes