Drawing automation, Insert Sketched Symbols and Auto Balloon.

Drawing automation, Insert Sketched Symbols and Auto Balloon.

wallin_a
Explorer Explorer
518 Views
3 Replies
Message 1 of 4

Drawing automation, Insert Sketched Symbols and Auto Balloon.

wallin_a
Explorer
Explorer

Hi all,

I'm working on a template for our assembly instructions at work, to automate more and get the same look/pattern on all new instructions. But easier said then done, i've been at it a time now, looked through all top 10 contributers post for hints and guides, but i feel i lack the knowledge for the workflow in the ilogic code, but im trying. Still i would be grateful if someone had some solution/tip on this. I attached a picture of the layout, it's broken down to 3 rules, and im trying to keep it simple if it's possible.

Thanks.

0 Likes
519 Views
3 Replies
Replies (3)
Message 2 of 4

A.Acheson
Mentor
Mentor

Hi @wallin_a 

Any chance you can attach your rules you have worked with and indicate where you would like to make changes? Placing sketch symbols and positioning is achievable. Here is an API sample if you have not allready seen a complete rule. Unfortuantely it is written in VBA so small tweaks are needed but the format is very similar to ilogic/VB.NET versions. 

 

Auto ballooning is by far the most difficult task in your list but is possible but very time consuming which is why alot of people tend not to use it.

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

wallin_a
Explorer
Explorer

Hi @A.Acheson ,

This is the code for the sketch symbols i was trying to use (it is from the forums, though it was used for textbox notes, but i thought i could make it work) should say that the sketch symbol is only a picture i inserted, the array section is unedited here. But it gives me,

"Error on line 60 in rule: SketchArray, in document: bp_test001.dwg

 Object reference not set to an instance of an object."

And aborts, placing the symbols ontop each other. My first thought was that something is wrong with the declaration, and i tested to add a textbox, but same error. Then i read about it "null reference" so i guess im mssing some logic here.

 

Sub Main
	
	'[ Set the Symbols To work With. They must be in the Library
	Names.add("ham2")
	Names.add("ham3")
	Names.add("test1")
	Names.add("test2")
			
	Dim Selection As String
	Do
		Selection = InputListBox("Prompt", Names, d0, Title := "Title", ListName := "List")
		If Len(Selection)<> 0 Then
		Notes.add(Selection)
		End If
	Loop While Len(Selection)>0
']
	
    Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument '  a reference to the drawing document.

	Dim oSketchSymLib As SketchedSymbolDefinitionLibrary'Getting Symbol from library ......\Design Data\Symbol Library\ 
	oSketchSymLib = oDrawDoc.SketchedSymbolDefinitions.SketchedSymbolDefinitionLibraries.Item("Library")

    Dim oSketchedSymbolDef As SketchedSymbolDefinition
	
	Dim oSketchedSymbol As SketchedSymbol

	Dim oSheet As Sheet
	oSheet = oDrawDoc.ActiveSheet
	 
	Dim oTG As TransientGeometry
	oTG = ThisApplication.TransientGeometry
	
	Notes.Reverse 'Reverse list to add first items selected last
	
	For Each Name In Notes 'Loop through collection and add symbol to drawing
	 
		oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.AddFromLibrary(oSketchSymLib, Name , True)'Add the Sketched Symbol from the library to local symbols before you can place it.
		
		Dim oTGPoint As Point2d
		oTGPoint = oTG.CreatePoint2d(0, 0)
	    oSketchedSymbol = oSheet.SketchedSymbols.Add(oSketchedSymbolDef, oTGPoint)' Add an instance of the sketched symbol definition to the sheet.
	Next
		
	MoveNote(oDrawDoc, oSheet, oTG)
	
	End Sub
	
	Dim Names As New ArrayList
	Dim Notes As New ArrayList
	Dim Name As String
	
	Sub MoveNote(oDrawDoc As DrawingDocument,oSht As Sheet,oTG As TransientGeometry)
	
	For Each Name In Notes 
		For Each sym As SketchedSymbol In oSht.SketchedSymbols'Loop through each symbol to identify object
			If Name = sym.Name Then
				
				Dim LSCX, LSCY As Double
				LSCX = oSht.Border.RangeBox.MinPoint.X'Left Sheet Corner
				LSCY =oSht.Border.RangeBox.MinPoint.Y'Left Sheet Corner

				Dim oTextBox As Inventor.TextBox
			    oTextBox = sym.Definition.Sketch.TextBoxes(1)
				
				Dim TextWidth, TextHeight As Double
				TextWidth = oTextBox.RangeBox.MaxPoint.X - oTextBox.RangeBox.MinPoint.X
				TextHeight = oTextBox.RangeBox.MaxPoint.Y - oTextBox.RangeBox.MinPoint.Y
				
				Dim oSpace As Double'give some space between symbols
				oSpace = 0.3
				
				Dim NewHeight As Double 'Stack the symbols starting from bottom
				NewHeight = (TextHeight) + NewHeight + oSpace 
				
				Dim oTGPoint As Point2d
				oTGPoint = oTG.CreatePoint2d(LSCX+TextWidth/2+oSpace, LSCY+NewHeight)
				sym.Position = oTGPoint
			End If
		Next
	Next
	End Sub

 

And for the ballooning part, i haven't started digging in it yet

0 Likes
Message 4 of 4

A.Acheson
Mentor
Mentor

Hi @wallin_a 

The code is a good start. One big item to note is that sketch symbols don't have a range box method so therefore it is highly difficult to find the border of one vs the other. You can only reference the position (insertion point). So really any attempt to prevent over lap would be through trial and error. There can be methods like drawing a border internally in the symbol but thst gets complicated very quickly.

 

For the moving sub I would either copy the existing and comment using it as a guide then comment reference to the text box objects as your looking to work with sketch symbol only. 

Comment/remove/ place outside code block commented these lines.

 

				Dim oTextBox As Inventor.TextBox
			    oTextBox = sym.Definition.Sketch.TextBoxes(1)
				
				Dim TextWidth, TextHeight As Double
				TextWidth = oTextBox.RangeBox.MaxPoint.X - oTextBox.RangeBox.MinPoint.X
				TextHeight = oTextBox.RangeBox.MaxPoint.Y - oTextBox.RangeBox.MinPoint.Y
				
				Dim oSpace As Double'give some space between symbols
				oSpace = 0.3
				
				Dim NewHeight As Double 'Stack the symbols starting from bottom
				NewHeight = (TextHeight) + NewHeight + oSpace 
				
				Dim oTGPoint As Point2d
				oTGPoint = oTG.CreatePoint2d(LSCX+TextWidth/2+oSpace, LSCY+NewHeight)
				sym.Position = oTGPoint

 

 What you should be left with is similar to this. Then you need to add in an offset of your choice. Bring back in pieces as you need.

 

Dim oTGPoint As Point2d
oTGPoint = oTG.CreatePoint2d(0, 0)
sym.Position = oTGPoint

 

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