Extracting view information for sketch symbols

Extracting view information for sketch symbols

Erik_Keating
Explorer Explorer
414 Views
2 Replies
Message 1 of 3

Extracting view information for sketch symbols

Erik_Keating
Explorer
Explorer

Hello,

 

I am currently using Ilogic automatically place and name custom view labels in drawings. The script goes through the sheet and for every view deletes any old labels, extracts the scale, view name, sheet number and view number and replaces the view label in roughly the center. The sketch symbol is a series of prompted entries and the info once placed is not associated. 

 

The issue I am running into is when I have to update any of the information on the view label I have to run the script again which deletes all the old labels and replace them with the new information. this move the labels which isn't really a problem its just kind of annoying. What I want is a method or property of the sketch object that tells you what the sketch symbol is linked to. I know there is "parent" but the documentation on that is pretty sparse. 

 

Is there an easier way of doing this I am missing?  Here is the script as it stands:

Sub Main()
	Dim oDoc As DrawingDocument = ThisDoc.Document
	Dim oSheets As Sheets = oDoc.Sheets
	Dim oSheet As Sheet
	Dim oViews As DrawingViews
	Dim oView As DrawingView
	Dim oSymbol As SketchedSymbol
	Dim oSymbols As SketchedSymbols
	Dim SymbolName = New String("View_label")
	
	
	'iterate through all of the sheets
	'For Each oSheet In oSheets
		'remove existing sketched symbols named View Label 
		oSheet = oDoc.ActiveSheet
		For Each oSymbol  In oSheet.SketchedSymbols
		If oSymbol.Definition.Name = SymbolName Then
		oSymbol.Delete
		Else 
		End If
		Next
		
	'set sheet active	
	oSheet.Activate
	'set a refernce to the drawing views collection
	oViews = oDoc.ActiveSheet.DrawingViews
		' Iterate through all of the views
		Dim ViewNum As Integer = 1
			
		For Each oView In oViews
			'removes old label styles 
			If oView.ShowLabel Then
				oView.ShowLabel = False
			End If
				
			'This places a sketched symbol with the name "View_Label"
			Dim oSymDef As SketchedSymbolDefinition
			'defind the sketch symbol to be inserted
			oSymDef = oDoc.SketchedSymbolDefinitions.Item(SymbolName)
			
			'autofill missing info for detail and section views 
			Dim sViewName As String
			If oView.Type = ObjectTypeEnum.kSectionDrawingViewObject Then
				sViewName = "SECTION: "& oView.Name & "-" & oView.Name
			Else If oView.Type = ObjectTypeEnum.kDetailDrawingViewObject Then
				sViewName = "DETAIL: " & oView.Name
			Else
				sViewName = oView.Name
				Logger.Debug(oView.AttributeSets.Type.ToString)
			End If
							
	
			'set a string array with values for the prompted entries found in the symbol
			Dim sPromptStrings(3) As String 
			sPromptStrings(0) = "SCALE: " & oView.ScaleString 'set to view scale
			sPromptStrings(1) = sViewName 'set to view name
			sPromptStrings(2) = ViewNum.ToString.PadLeft(3,"0")
			sPromptStrings(3) = Mid(oSheet.Name, InStr(1, oSheet.Name, ":") + 1).PadLeft(3,"0")
			
			
			'set the position for the sketched symbol to be inserted 
			' and spaced off of the selected view center
			Dim oPosition As Point2d : oPosition = oView.Center
		
			oPosition.Y = oPosition.Y - (oView.Height / 2 + 0.6)
			'insert the sketched symbol and set the prompted entries
			oSymbol = oSheet.SketchedSymbols.Add(oSymDef, oPosition, 0, 1, sPromptStrings)
			ViewNum+=1
		Next
End Sub
0 Likes
415 Views
2 Replies
Replies (2)
Message 2 of 3

A.Acheson
Mentor
Mentor

Hi @Erik_Keating ,

So a partial answer to  your question is the sketch symbol seems to become attached to the view based on an annotation attachment method by positioning  the symbol within the view border. I am not sure there is API access to know if this is connected to anything or not. 

 

In relation to your label workflow would it be easier to write the label information in to the label via text rather than into a sketch symbol? This way you can work with the build in labels and avoid prompted entry and an extra object to manage. 

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 3

WCrihfield
Mentor
Mentor

Hi @Erik_Keating.  There is a way to tell if the SketchedSymbol is attached to anything or not, but its not super simple.  The SketchedSymbol object has a property called Leader, which may return a Leader object, even if you are not using any leaders.  It may just not be shown visibly because there is a LeaderVisible property.  And that Leader object has a couple properties you should check (HasRootNode & RootNode).  If HasRootNode returns True, then use the the RootNode property to get a reference to the LeaderNode object it represents.  Then check the LeaderNode's AttachedEntity property to get the GeometryIntent object it represents.  Then check the GeometryIntent's IntentType property (returns a variation of the IntentTypeEnum) to see if it represents the 'kGeometryIntent' type.  If so, then get the GeometryIntent.Geometry property's value to a variable (as an Object, because it could be many Types of things).  Then you can check if the Type of that geometry object is a DrawingCurve.  If so, you can use its Parent property to get the DrawingView object that it is associated with.  Of course it may be another Type of object too, so it may require more code to check for multiple Types, and how to respond to those specific Types if encountered.  Whew!  That is a long and arduous process, with a lot of 'If's and checks in there, so I don't know if it will be worth it or not.  Just saying that is the logical path to get there, if possible.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)