Swapping Sketch Symbols (Different language set)

Swapping Sketch Symbols (Different language set)

jaco011
Advocate Advocate
682 Views
3 Replies
Message 1 of 4

Swapping Sketch Symbols (Different language set)

jaco011
Advocate
Advocate

Hi all,

 

I hope someone can help me. I want to PDF mine .idw in multiple languages. All the text is placed in the borders & sketch symbols. For each sketch symbol I have the standard language set and some other sets. (For example sketch symbol 01Standard and 01Scandinavian, I used these also in the code to make it clear names, in reality these are more complex).

 

I already managed to create an form (see picture below). 'Get language options' button creates a multi value parameter with the language options (only needed the first time used in a drawing, or when an language is added). The idea is that you select the goal language and push 'Translate'. Translate rule should swap the borders and sketch symbols to the selected language. (Each sketch symbol and on each page)

JLassche_0-1634560300230.png

JLassche_1-1634560360648.png

 

I have already the code shown below. If a test separate parts it works, but as a whole I don't get it working. Also I struggle to add the "for each sheet". 

Is there someone able to help me? 

 

Sub Main
	'check file type 
	If ThisDoc.Document.DocumentType <> kDrawingDocumentObject Then
	MessageBox.Show("Document is not a drawing.", "iLogic",MessageBoxButtons.OK,MessageBoxIcon.Warning)
	Return
	End If


	'Sketch symbols swap to standard
	If Parameter ("LanguageOptions") = "Standard"
		For Each oSheet In oDrawDoc
				'Define which symbol should be swapped by which one
				SwapSymbols("01Scandinavian", "01Standard")
				SwapSymbols("01Arabic", "01Standard")
				SwapSymbols("02Scandinavian", "02Standard")
				SwapSymbols("02Arabic", "02Standard")
		Next
	End If
	
	'Sketch symbols swap to Arabic
	
	'Sketch symbols swap to Scandinavian
		
	'Title blocks swap to standard
	
	'Title blocks swap to Arabic
	
	'Title blocks swap to Scandinavian
	
End Sub

	'Define the drawing document
	Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument

	'Define the drawing sheet
	Dim oSheet As Sheet = oDrawDoc.ActiveSheet

	'create insertion point, coordinates - are cm 
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	Dim oInsertionPoint As Point2d

Sub SwapSymbols (SymbolOriginal As String, SymbolTranslated As String)
	For Each oSymbol In oDrawDoc.ActiveSheet.SketchedSymbols
		'look for the symbol by name
		If oSymbol.Name = SymbolOriginal Then
	
			'get the symbol insert point
			oSymbPoint = oSymbol.Position
			oInsertionPoint = oTG.CreatePoint2d(oSymbPoint.X,oSymbPoint.Y)
		
			'get the symbol scale
			oSymbScale = oSymbol.Scale
		
			'delete SymbolOriginal
			oSymbol.Delete
			
			'Place SymbolTranslated (name symbol, position, rotation, scale, 
			oSymbol_2 = oSheet.SketchedSymbols.Add(SymbolTranslated, oInsertionPoint, 0, oSymbScale, Nothing)
		End If
	Next 
End Sub

 

0 Likes
Accepted solutions (1)
683 Views
3 Replies
Replies (3)
Message 2 of 4

A.Acheson
Mentor
Mentor

The API help has some good samples on working with symbols. Just type in symbol into the search and you can navigate to some samples. Although they may be in VBA the process will be similar. 

Here is an example of looping through each sheet.

 

Here is also a post to add a symbol from the symbol libraries. There is additional adding to folders but you can comment out those sections. 

 

Dim oSketchSymLib As SketchedSymbolDefinitionLibrary
oSketchSymLib = oDrawDoc.SketchedSymbolDefinitions.SketchedSymbolDefinitionLibraries.Item(oSymbolDrawingName)

I would suggest you add your symbols to the library so that you have a central location to update them from if you need to make a global change. The code will then fetch the update symbol if you build in a refresh from library button or simply toggle the language. 

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

jaco011
Advocate
Advocate

Thanks for answering my question. I will look into that! We now have an plug-in to update the sketch symbols, but maybe the library is a nice additon.

0 Likes
Message 4 of 4

JelteDeJong
Mentor
Mentor
Accepted solution

I could not test your code but I did see some things that I did not expect. That have been changed in the code and i expect that it works better now.

        'check file type 
        If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
            MessageBox.Show("Document is not a drawing.", "iLogic", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Return
        End If

        If Parameter("LanguageOptions") = "Standard" Then
            For Each sheet As Sheet In ThisDoc.Document.Sheets
                sheet.Activate()

                'Define which symbol should be swapped by which one
                SwapSymbols(sheet, "01Scandinavian", "01Standard")
                SwapSymbols(sheet, "01Arabic", "01Standard")
                SwapSymbols(sheet, "02Scandinavian", "02Standard")
                SwapSymbols(sheet, "02Arabic", "02Standard")

            Next
        End If

        'Sketch symbols swap to Arabic

        'Sketch symbols swap to Scandinavian

        'Title blocks swap to standard

        'Title blocks swap to Arabic

        'Title blocks swap to Scandinavian

    End Sub



    Sub SwapSymbols(sheet As Sheet, SymbolOriginal As String, SymbolTranslated As String)
        Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
        Dim sketchSymbols As SketchedSymbols = sheet.SketchedSymbols
        For Each oSymbol As SketchedSymbol In sketchSymbols
            'look for the symbol by name
            If oSymbol.Name = SymbolOriginal Then

                'get the symbol insert point
                Dim oSymbPoint = oSymbol.Position
                Dim oInsertionPoint = oTG.CreatePoint2d(oSymbPoint.X, oSymbPoint.Y)

                'get the symbol scale
                Dim oSymbScale = oSymbol.Scale

                'delete SymbolOriginal
                oSymbol.Delete()

                'Place SymbolTranslated (name symbol, position, rotation, scale, 
                sheet.SketchedSymbols.Add(SymbolTranslated, oInsertionPoint, 0, oSymbScale, Nothing)
            End If
        Next
    End Sub

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com