Differentiate sheet metal parts in iLogic

Differentiate sheet metal parts in iLogic

machiel.veldkamp
Collaborator Collaborator
2,361 Views
5 Replies
Message 1 of 6

Differentiate sheet metal parts in iLogic

machiel.veldkamp
Collaborator
Collaborator

Hey all!


I made a handy iLogic rule the other day. 

 

Sub Main()
	'Determines if there is a flat pattern
	Dim oDoc As PartDocument
	oDoc = ThisDoc.Document
	'ensure this part has a flat pattern
	Dim oSMDef As SheetMetalComponentDefinition
	oSMDef = oDoc.ComponentDefinition
	
	If oSMDef.FlatPattern Is Nothing Then
		'Warns the user there is no flat pattern
		'MessageBox.Show("This file has no flat pattern", "iLogic")
	Else
		Extents
	End If
End Sub

Sub Extents()
	extents_length = SheetMetal.FlatExtentsLength
	extents_width = SheetMetal.FlatExtentsWidth
	LengthFrac = Round(SheetMetal.FlatExtentsLength, 0)
	WidthFrac = Round(SheetMetal.FlatExtentsWidth, 0)
	Dim oValue As String
	Dim param As Parameter
	
		If extents_width > extents_length Then
			oValue = (WidthFrac & "x" & LengthFrac)
			
			iProperties.Value("Custom", "DIMENSIONS") = oValue
		Else
			oValue = (LengthFrac & "x" & WidthFrac)
			iProperties.Value("Custom", "DIMENSIONS") = oValue
	End If
End Sub

We use this to put the extents of flat patterns in the partslists on drawings. I attach the rule to the .ipt trigger 'before save' and 'when geometry changes'

 

I want to attach this iLogic to the template .ipt however. 

The rule as it is now isn't suited for this yet however. When you run this rule on a non-sheet metal .ipt it will crash. 

 

Thats why I want to change it so the iLogic rule doesn't do anything except when the following conditions are true:

 

 

part.ipt is a sheet metal part.

&

part.ipt has a flat pattern


also if part.ipt breaks and no longer has a flat pattern the DIMENSIONS value should be empty. 

 

 

 

First off I need to know how I can differentiate between a normal part and a sheet metal part. 

 

Can anyone give me a hand here? 

 

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

___________________________
0 Likes
Accepted solutions (1)
2,362 Views
5 Replies
Replies (5)
Message 2 of 6

machiel.veldkamp
Collaborator
Collaborator
Accepted solution
Sub Main()
	Dim oDoc As PartDocument
	oDoc = ThisDoc.Document
	'ensure this part is a Sheet Metal Part
	If oDoc. SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}"
		Exit Sub
	End If
	
	Dim oSMDef As SheetMetalComponentDefinition
	oSMDef = oDoc.ComponentDefinition
	
	'Determines if there is a flat pattern
	If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
		If oSMDef.FlatPattern Is Nothing Then
			'No Flat Pattern Exists
			MakeFlatPattern
		Else
			'There is a Flat Pattern
			GetExtents
			GetThickness
		End If
	Else 
		MessageBox.Show("Else - Dit is GEEN Flat Pattern", "Title")
	End If
End Sub

Sub GetExtents()
	extents_length = SheetMetal.FlatExtentsLength
	extents_width = SheetMetal.FlatExtentsWidth
	LengthFrac = Round(SheetMetal.FlatExtentsLength, 0)
	WidthFrac = Round(SheetMetal.FlatExtentsWidth, 0)
	Dim oValue As String
	Dim param As Parameter
	
		If extents_width > extents_length Then
			oValue = (WidthFrac & "x" & LengthFrac)
			
			iProperties.Value("Custom", "DIMENSIONS") = oValue
		Else
			oValue = (LengthFrac & "x" & WidthFrac)
			iProperties.Value("Custom", "DIMENSIONS") = oValue
	End If
End Sub

Sub GetThickness()
	'Get sheet Metal Thickness - Set Description as SHEET "Thickness"mm
	Dim oThickness As String
	oThickness = Parameter("Thickness")
	iProperties.Value("Project", "Description") = "SHEET " & oThickness  & "mm"
End Sub


Sub MakeFlatPattern()
	Dim oDoc As PartDocument
	oDoc = ThisDoc.Document
	Dim oSMDef As SheetMetalComponentDefinition
    oSMDef = oDoc.ComponentDefinition
    Try 
		oSMDef.Unfold
		oSMDef.FlatPattern.ExitEdit
	Catch
		'Failed to make Flat Pattern
		MessageBox.Show("Failed to make a Flat Pattern", "ERROR")
	End Try
End Sub

 

This is what I wanted

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

___________________________
Message 3 of 6

machiel.veldkamp
Collaborator
Collaborator
'THIS DOCUMENT IS CREATED BY MACHIEL VELDKAMP IN 2016. 
'THIS CODE IS MEANT FOR AUTOMATICALLY DIMENSIONING FLAT PATTERNS ON THE STANDARD .DWG OF RELCO EUROPE

Sub Main()
	Dim oDoc As PartDocument
	oDoc = ThisDoc.Document
	'ensure this part is a Sheet Metal Part - If not: exit this iLogic Rule ASAP
	If oDoc.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}"
		Exit Sub
	End If
	
	Dim oSMDef As SheetMetalComponentDefinition
	oSMDef = oDoc.ComponentDefinition
		'Determines if there is a flat pattern
	If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
		If oSMDef.FlatPattern Is Nothing Then
			'No Flat Pattern Exists
			iProperties.Value("Custom", "DIMENSIONS") = "N/A"
		Else
			'There is a Flat Pattern
			GetExtents
			GetThickness
		End If
	Else 
		MessageBox.Show("THIS IS NO SHEET METAL", "ERROR")
	End If
	
End Sub

Sub GetExtents()
	LengthFrac = Round(SheetMetal.FlatExtentsLength, 0)
	WidthFrac = Round(SheetMetal.FlatExtentsWidth, 0)
	Dim oValue As String
	If WidthFrac > LengthFrac Then
		oValue = (WidthFrac & "x" & LengthFrac)
		
		iProperties.Value("Custom", "DIMENSIONS") = oValue
	Else
		oValue = (LengthFrac & "x" & WidthFrac)
		iProperties.Value("Custom", "DIMENSIONS") = oValue
	End If
End Sub

Sub GetThickness()
	'Get sheet Metal Thickness - Set Description as SHEET "Thickness"mm
	Dim oThickness As String
	oThickness = Parameter("Thickness")
	iProperties.Value("Project", "Description") = "SHEET " & oThickness  & "mm"
End Sub

Updated code. 

 

 

Removed the automatic Flat Pattern maker. That wasn't practical at all. 

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

___________________________
Message 4 of 6

Anonymous
Not applicable

very nice solution.

can please refer any material for learning and developing such thing for inventor.

what you have done is beyond iLogic provided by inventor.

0 Likes
Message 5 of 6

MechMachineMan
Advisor
Advisor

Great resources provided by autodesk on this:

 

https://knowledge.autodesk.com/support/inventor-products/learn-explore/caas/simplecontent/content/au...

 

http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-5901102A-F148-4CD4-AF50-26E2AFDEE6A7

 

Also, look up any documentation/guides/elearning courses you can on programming in vba / vb.net.

 

 


--------------------------------------
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 6 of 6

Anonymous
Not applicable
Thanks a lot for your reply with information.
0 Likes