(iLogic/Drawing) Creating Sketch/Text w/ style

JoãoASilva
Advocate

(iLogic/Drawing) Creating Sketch/Text w/ style

JoãoASilva
Advocate
Advocate

Hello!

 

I'm trying to create a sketch on my drawing with the text: "Não Produzir!" (Not for Reproducing!)

Adding the text as sketch (or as a "Annotate>Text") is fine by me.

 

My code will also change the style of the Title Block references to the model, in all the document sheets (wich I don't want).

Dim oDrawingDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDrawingDoc.ActiveSheet

oSheetMidX = (ThisDrawing.ActiveSheet.Width * 0.1) / 2
oSheetMidY = (ThisDrawing.ActiveSheet.Height * 0.1) / 2

oTrans = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument,"Não Produzir!")

Dim oSketch As DrawingSketch
oSketch = oDrawingDoc.ActiveSheet.Sketches.Add
oSketch.Name = "• Não Produzir •"
oSketch.Edit

Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry

Dim sText As String
sText = "Drawing Notes"
Dim oTextBox As TextBox
oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(0, 0), "")

oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(oSheetMidX, oSheetMidY), "Não Produzir!")
oTextBox.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter
oTextBox.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextMiddle
oSketch.TextBoxes.Item(1).Style.Bold = True
oSketch.TextBoxes.Item(1).Style.FontSize = "4.2"

oSketch.ExitEdit
	
oTrans.End

 Before firing rule:

JoãoASilva_0-1617294771703.png

After:

JoãoASilva_1-1617294848823.png

 

Does anyone know how to only apply the new style on the sketch I created?

Thanks!

João Silva

Mechanical Engineer

 

0 Likes
Reply
Accepted solutions (2)
1,484 Views
5 Replies
Replies (5)

A.Acheson
Mentor
Mentor

I usually handle these kind of disclaimer messages with a sketch symbol everything is self contained and Leaves out the complicated sketches, fonts changes etc, you can add them also if running a update revision block and print to  PDF on batch update files.

 

Theory:

I can only think that the text in the title block is also part of a sketch or has the same style as the newly created text box and now the style font is being changed locally in the drawing? 

Text Styles; global, local are a bit of nightmare.

 

Can you supply screenshots of the font dialogue box with the title block when editing? Without the drawing file we can only guess what is happening. Clicking below the font and on the font will bring back different results if overwritten from the global style. 

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

JoãoASilva
Advocate
Advocate

Hi @A.Acheson ,

 

I changed the code based on your reply.

So I tried to use sketch symbols instead, so I can apply to other cases.

 

I'm having trouble checking and deleting existing ones:

Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDrawDoc.ActiveSheet

'Get active sheet center point
oSheetMidX = (ThisDrawing.ActiveSheet.Width * 0.1) / 2
oSheetMidY = (ThisDrawing.ActiveSheet.Height * 0.1) / 2

'Start Transaction Manager
oTrans = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument,"Não Produzir!")

'Check if sketch symbol exists and has right size
'If yes - returns
If oSheet.SketchedSymbols.Item(1).Name = "A3_NP" And oSheet.Size = DrawingSheetSizeEnum.kA3DrawingSheetSize Then
	Return
Else If oSheet.SketchedSymbols.Item(1).Name = "A2_NP" And oSheet.Size = DrawingSheetSizeEnum.kA2DrawingSheetSize Then
	Return
End If

'If not - delete and insert
'Delete existing symbol
Try
	oSheet.SketchedSymbols.Item(1).Delete
Catch
End Try

Dim oSketchedSymbolDef As SketchedSymbolDefinition

'Define sketch symbol by sheet size
If oSheet.Size = DrawingSheetSizeEnum.kA3DrawingSheetSize Then
	oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Item("A3_NP")
Else If oSheet.Size = DrawingSheetSizeEnum.kA2DrawingSheetSize Then
	oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Item("A2_NP")
End If

'Create Insertion Point
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
Dim oInsertionPoint As Point2d = oTG.CreatePoint2d(oSheetMidX, oSheetMidY)

'Insert Sketched Symbol
Dim oSketchedSymbol As SketchedSymbol = oSheet.SketchedSymbols.Add(oSketchedSymbolDef, oInsertionPoint, 0, 1, Nothing)

'End Transaction Manager
oTrans.End

 Thoughts?

João Silva

Mechanical Engineer

 

0 Likes

WCrihfield
Mentor
Mentor

What kinds of trouble are you having?  Is it not doing anything?  Is it showing any error messages?  If it is showing error messages, please posts screenshots of the contents in both tabs of the error message.

Is it possible that both sketched symbols aren't present in the target sheet?

 

The definitions for the sketched symbols are originally only within the drawing document itself, not in each of the sheets.

The sketched symbol object will only be found on a sheet after you have 'placed' the symbol on that sheet.  After you place a sketch symbol on a sheet, there will be a browser node (folder) for 'Sketch Symbols' somewhere under that sheet's node in the model browser tree, and when you delete that symbol, if there are no others already on that sheet, that node (folder) is also deleted, so they can't be retrieved from that sheet anymore.  If you want to place a symbol on that sheet, and there isn't already one on that sheet, you will have to add it from the symbol definitions of that drawing document, not from the sheet.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

WCrihfield
Mentor
Mentor
Accepted solution

Maybe try this version, and see if it works better for you.

The code within the two checks could probably be set-up as a sub routine, to reduce code, but I just left it all in one place for now.  Basically, it first finds the two main sketch symbol definitions, and if they aren't found, it lets you know then exits.  Then it gets the active sheet and its center point, then starts the main checking/doing process.  It first checks to see if there are 'any' symbols on the sheet, if not, it creates the one needed.  If there are some symbols on the sheet, it loops through them, deleting any that aren't our target one, and if the target one is not found, it creates it.

Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument

'find/get the two sketched symbol definitions we will be working with
Dim oA3NP, oA2NP As SketchedSymbolDefinition
For Each oSSDef As SketchedSymbolDefinition In oDrawDoc.SketchedSymbolDefinitions
	If oSSDef.Name = "A3_NP" Then oA3NP = oSSDef
	If oSSDef.Name = "A2_NP" Then oA2NP = oSSDef
Next
If oA3NP Is Nothing Then
	MsgBox("Could't find the SketcheSymbolDefinition named 'A3_NP'.  Exiting.",,"")
	Exit Sub
End If
If oA2NP Is Nothing Then
	MsgBox("Could't find the SketcheSymbolDefinition named 'A2_NP'.  Exiting.",,"")
	Exit Sub
End If

Dim oSheet As Sheet = oDrawDoc.ActiveSheet
Dim oSSymbs As SketchedSymbols = oSheet.SketchedSymbols

'Get active sheet center point
oSheetMidX = (oSheet.Width * 0.1) / 2
oSheetMidY = (oSheet.Height * 0.1) / 2
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
'Create Insertion Point
Dim oInsPt As Point2d = oTG.CreatePoint2d(oSheetMidX, oSheetMidY)

'Start Transaction
oTrans = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument,"Não Produzir!")

Dim oExists As Boolean = False
If oSheet.Size = DrawingSheetSizeEnum.kA3DrawingSheetSize Then
	If oSSymbs.Count = 0 Then
		oSSymbs.Add(oA3NP, oInsPt, 0, 1)
	Else
		For Each oSS As SketchedSymbol In oSSymbs
			If oSS.Name = "A3_NP" Then
				oExists = True
			Else
				oSS.Delete
			End If
		Next
		If oExists = False Then
			oSSymbs.Add(oA3NP, oInsPt, 0, 1)
		End If
	End If
ElseIf oSheet.Size = DrawingSheetSizeEnum.kA2DrawingSheetSize Then
	If oSSymbs.Count = 0 Then
		oSSymbs.Add(oA2NP, oInsPt, 0, 1)
	Else
		For Each oSS As SketchedSymbol In oSSymbs
			If oSS.Name = "A2_NP" Then
				oExists = True
			Else
				oSS.Delete
			End If
		Next
		If oExists = False Then
			oSSymbs.Add(oA2NP, oInsPt, 0, 1)
		End If
	End If
End If

'End Transaction Manager
oTrans.End

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

JoãoASilva
Advocate
Advocate
Accepted solution

Hi @WCrihfield,

 

Seems like I was having trouble with the "Return" statement.

I was trying to set up the rule in 1 drawing only. After that, I was going to see how I could "call" the sketch symbol, If the drawing file didn't had it.

 

So I created 2 sketch symbols and added them to the sketch library.

Had to change the directory in the Application Options to the network. (if someone wants to do the same)

 

I updated the drawing template, but it can happen to open an old drawing and need to place the symbol.

 

I made some tweaks to your code, and it seems to be working perfectly for me!

Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument

'find/get the two sketched symbol definitions we will be working with
Dim oA3NP, oA2NP As SketchedSymbolDefinition
For Each oSSDef As SketchedSymbolDefinition In oDrawDoc.SketchedSymbolDefinitions
	If oSSDef.Name = "A3_NP" Then oA3NP = oSSDef
	If oSSDef.Name = "A2_NP" Then oA2NP = oSSDef
Next

'Use symbol from library if not found in the drawing If oA3NP Is Nothing Then oA3NP = ThisDrawing.Document.SketchedSymbolDefinitions.AddFromLibrary("Template.idw", "A3_NP") End If If oA2NP Is Nothing Then oA2NP = ThisDrawing.Document.SketchedSymbolDefinitions.AddFromLibrary("Template.idw", "A2_NP") End If Dim oSheet As Sheet = oDrawDoc.ActiveSheet Dim oSSymbs As SketchedSymbols = oSheet.SketchedSymbols 'Get active sheet center point oSheetMidX = (oSheet.Width * 1) / 2 'Scale is beeing defined by the oSSymbs.Add oSheetMidY = (oSheet.Height * 1) / 2 'Scale is beeing defined by the oSSymbs.Add Dim oTG As TransientGeometry = ThisApplication.TransientGeometry 'Create Insertion Point Dim oInsPt As Point2d = oTG.CreatePoint2d(oSheetMidX, oSheetMidY) 'Start Transaction oTrans = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument,"Não Produzir!") Dim oExists As Boolean = False If oSheet.Size = DrawingSheetSizeEnum.kA3DrawingSheetSize Then If oSSymbs.Count = 0 Then oSSymbs.Add(oA3NP, oInsPt, 0, 1) Else For Each oSS As SketchedSymbol In oSSymbs If oSS.Name = "A3_NP" Then oExists = True Else oSS.Delete End If Next If oExists = False Then oSSymbs.Add(oA3NP, oInsPt, 0, 1) '1 defines scale End If End If ElseIf oSheet.Size = DrawingSheetSizeEnum.kA2DrawingSheetSize Then If oSSymbs.Count = 0 Then oSSymbs.Add(oA2NP, oInsPt, 0, 1) '1 defines scale Else For Each oSS As SketchedSymbol In oSSymbs If oSS.Name = "A2_NP" Then oExists = True Else oSS.Delete End If Next If oExists = False Then oSSymbs.Add(oA2NP, oInsPt, 0, 1) '1 defines scale End If End If End If 'End Transaction Manager oTrans.End

 

 Thank you!

João Silva

Mechanical Engineer

 

0 Likes

Type a product name