iLogic for Sketched Symbols

iLogic for Sketched Symbols

Anonymous
Not applicable
4,901 Views
7 Replies
Message 1 of 8

iLogic for Sketched Symbols

Anonymous
Not applicable

OK. I've seen lots of different posts that kind of touch on this subject and I have borrowed several fragments of code, but now I need to unify them.

 

Essentially, I have custom iProperty field (Yes or No). If the Custom iProperty field is set to yes, I need iLogic to drop in a sketched symbol. If it gets set back to no, I need it to delete that sketched symbol and drop in a different one. Likewise, I need the routine to check to see if either of the sketched symbols exist and then not drop in a new one on top of the old one.

 

Any ideas?

 

 

0 Likes
Accepted solutions (1)
4,902 Views
7 Replies
Replies (7)
Message 2 of 8

MechMachineMan
Advisor
Advisor
Yes. Event Trigger. Code that runs through and checks the iProperty field. Code that checks for the symbol and what symbol. Then code that inserts/deletes based upon that.

--------------------------------------
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 8

Curtis_Waguespack
Consultant
Consultant

Hi sco.smith,

 

Here's a quick example.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Sub Main
	'define symbol name to work with
	sSymbol_01 = "MySketchedSymbol"
	oDrawDoc = ThisApplication.ActiveEditDocument
	
	'capture the current active sheet 
	Dim oCurrentNumber  As Sheet
	oCurrentNumber  = oDrawDoc.ActiveSheet
	
	'make sure custom iproperty exists
	'and get user input
	Call Create_Custom_iProp()
	
	'run a sub based on the user input returned
	If iProperties.Value("Custom", "InclucdeSymbol") = True Then
		Call PlaceSymbols()
	Else
		Call DeleteSymbols()
	End If
	
	'activate the original current sheet
	oCurrentNumber.activate 
End Sub

'''declare variables passed between subs
'Define the drawing document
Dim oDrawDoc As DrawingDocument
'Define the symbols to look for
Dim sSymbol_01 As String
'create the sketched symbol definition
Dim oSymDef_01 As SketchedSymbolDefinition

'creates or sets the iproperty
'based on user input
Sub Create_Custom_iProp()
	Dim CustomPropSet As PropertySet
	CustomPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")
	
	'Define the Boolean 
	'a boolean is needed to create an iproperty as a true/false 
	Dim oBoolean As Boolean
	
	'get user input
	'default is True (yes)
	oBoolean = InputRadioBox("Include " & sSymbol_01 & " ?", "Yes (place) ", "No (Delete)", True, "iLogic") 
	
	Try
		'try to set the iproperty 
		iProperties.Value("Custom", "InclucdeSymbol") = oBoolean
	Catch
		'catch error when iproperty doesn't exist and create it
		CustomPropertySet.Add("", "InclucdeSymbol")
		'then set it
		iProperties.Value("Custom", "InclucdeSymbol") = oBoolean
	End Try
End Sub

'place symbols
Sub PlaceSymbols()
	'create insertion point, coordinates - are cm 
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	Dim oInsertionPoint As Point2d
	
	'define the insert point for the symbol
	oInsertionPoint = oTG.CreatePoint2d(16,9) ' X = 16 cm , Y = 9 cm
	'define symbol Definition to use
	oSymDef= oDrawDoc.SketchedSymbolDefinitions.Item(sSymbol_01​)
	
	' Iterate through the sheet
	For Each oSheet In oDrawDoc.Sheets
		oSheet.Activate
		'insert the new symbol
		'Nothing is used when teh symbol has no prompted entry
		oSym = oSheet.SketchedSymbols.Add(oSymDef,oInsertionPoint​,0,1,Nothing)	
	Next 'next sheet
End Sub

'delete symbols by name
Sub DeleteSymbols()
	' Iterate through the sheet
	For Each oSheet In oDrawDoc.Sheets
	oSheet.Activate
	'Iterate through each symbol in the active sheet
		For Each oSymbol In oSheet.SketchedSymbols
			'look for the symbol by name
			If oSymbol.Name = sSymbol_01 Then
			'delete the symbol
			oSymbol.Delete
			Else 
			End If
		Next 'next symbol
	Next 'next sheet
End Sub

EESignature

Message 4 of 8

Anonymous
Not applicable

Thanks Curtis!

 

That's much cleaner than the spaghetti code I bodged together.

 

Just out of curiosity, is there an iLogic command reference/syntax/primer floating around out there? Most of the stuff I have done has been created by "cutting and pasting" from the shoulders of giants.

 

I'd like to dive much deeper.

 

Thanks,

 

Scott

0 Likes
Message 5 of 8

Curtis_Waguespack
Consultant
Consultant

Hi  sco.smith,

 

You find Inventor API help info at this link:

http://inventortrenches.blogspot.com/2013/10/ilogic-how-to-learn-inventors.html

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 6 of 8

Anonymous
Not applicable

Wunderbar! Thank you so much! This is very helpful.

 

By any chance do you have a fragment of iLogic that would import sketched symbols from one idw to another? I've added some to our main template and I'd like for my users to be able to click on an external rule to just grab these symbols and stick them in their drawing without having to rely on the drawing resource transfer wizard. Likewise, is it possible to import a local ilogic rule from the template to another idw?

 

Thanks again in advance,

 

Scott

0 Likes
Message 7 of 8

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi  sco.smith,

 

I had exactly that on hand, but it was doing a lot of other things specific to my needs. Here is a stripped down version that you can give a try. Just change the template pointer and the list of symbols as needed.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

Sub Main
	'define this document
	oDrawDoc = ThisDoc.Document
	'define template file
	oTemplateFile = "\\server\departments\CAD\Inventor\Templates\Standard.idw"   
	
	'capture the current active sheet 
	Dim oCurrentNumber  As Sheet
	oCurrentNumber  = oDrawDoc.ActiveSheet
	
	'get symbol names
	Call SymbolNames()	
	
	'get/place symbols
	Call PlaceSymbols()
	
	'activate the original current sheet
	oCurrentNumber.activate 
End Sub

'[ Declare variables passed between subs
'Define the drawing document
Dim oDrawDoc As DrawingDocument
'Define the symbols to look for
Dim sSymbol_01 As String
'create the sketched symbol definition
Dim oSymDef_01 As SketchedSymbolDefinition
'define array list
Dim oSymbolList As New ArrayList
'identify the source template file that contains the symbol definitions
Dim oTemplateFile As String 

']

Sub SymbolNames()

	'add the symbols to work with to the array list 
	'and setup standard insert coordinates for each symbol. Note: coordinates are in cm 
	'assumes a symbol of this name is present in the template
	'uses vertical bar as seperator
	'uses underscore as seperator X_Y seperator
	oSymbolList.add("Standard Notes" & "|" & "3_2") 
	oSymbolList.add("Approval Stamp" & "|" & "6_2") 
	oSymbolList.add("CallOut" & "|" & "Null") 'this symbol has no standard insert coordinates
	oSymbolList.add("MECHANICAL NOTES" & "|" & "1.5_2.6")
	
End Sub

Sub PlaceSymbols()

    'open the template         
    Dim strSourceIDW As DrawingDocument
    strSourceIDW = ThisApplication.Documents.Open(oTemplateFile, False)
    
	'For Each oItem in oSymbolList
	For oItem = 0 To oSymbolList.Count - 1
		'split the arraylist value into words using the vertical bar character
		Dim words As String() = oSymbolList.Item(oItem).Split(New Char() {"|"c})
		'result:
		'words(0) = symbol name
		'words(1) = insert coordinates
		
		'get the symbol definition from the template	
		Dim oTemplateSymbol As SketchedSymbolDefinition
		Try
		oTemplateSymbol = strSourceIDW.SketchedSymbolDefinitions.Item(Trim(words(0))) 
		Catch
		'MessageBox.Show(words(0) & " not found in ", "iLogic")
		MessageBox.Show(words(0) & " not found in tempate file.", "iLogic")
		Goto NotFound_Exception
		End Try
		
		'check for existing symbol definition (just in case)
		'if not found, create new symbol definition
		'and place the definition In the drawing resources folder
		Dim oNewSymbol As SketchedSymbolDefinition
		Dim oSymDefs As SketchedSymbolDefinitions = oDrawDoc.SketchedSymbolDefinitions
		For Each SketchedSymbolDefinition In oSymDefs
			If  oSymDefs.Item(Trim(words(0))).Name = Trim(words(0)) Then
			'set flag
			oSymbolExists = True
			End If
		Next
		
		If oSymbolExists = True Then 
		'resue 
		oNewSymbol = oDrawDoc.SketchedSymbolDefinitions.Item(Trim(words(0))) 
		Else
		'copy and create new
		oNewSymbol = oTemplateSymbol.CopyTo(oDrawDoc)	
		End If
		
		'create insertion point
		Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
		Dim oInsertionPoint As Point2d
		
		'add the symbols to each sheet
		For Each oSheet In oDrawDoc.Sheets
			oSheet.Activate
			'check for null insert point
			'place symbol if insert point is not null
			If Trim(words(1)) <> "Null" Then
			'split string using underscore
			Dim oXY As String() = Trim(words(1)).Split(New Char() {"_"c})
			'convert strings to Double
			oX = CDblAny(oXY(0)) 'X coordinate
			oY = CDblAny(oXY(1)) 'Y coordinate
			'insert symbols	(assumes symbol has no prompted entry)	
			oInsertionPoint = oTG.CreatePoint2d(oX,oY)
			'SketchedSymbols.Add(SymbolDefinition, InsertPoint,Rotation,Scale,PromptStrings) 
			oSymbol = oSheet.SketchedSymbols.Add(oNewSymbol,oInsertionPoint,0,1,Nothing)
			End If
		Next 'next sheet
		
		NotFound_Exception:
		
	Next 'next symbol
	
	'close the template/source file
	strSourceIDW.Close()
End Sub

EESignature

Message 8 of 8

Anonymous
Not applicable

This is really above and beyond! Thank you so much!

 

Scott

0 Likes