Conditional text formatting

Conditional text formatting

vvvxxvvv333
Enthusiast Enthusiast
964 Views
11 Replies
Message 1 of 12

Conditional text formatting

vvvxxvvv333
Enthusiast
Enthusiast

There is a custom iProrety "Db" which has two values "Painted" or "Furner" In the drawing, I add a text that displays this value. With this expression

FormattedText= "<Property Document='model' PropertySet='User Defined Properties' Property='Db' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='28'>Db</Property>"

 

If you change the value in the part, the text in the drawing changes automatically. And it's convenient.

But I need the text to be formatted according to the condition, if the value = “Painted” the text should be italic and if = “Furner” bold

What should I change to make this happen automatically?

Accepted solutions (3)
965 Views
11 Replies
Replies (11)
Message 2 of 12

Curtis_Waguespack
Consultant
Consultant

Hi @vvvxxvvv333 

 

Thanks for providing the example files!


See examples below.

 

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

 

 

 

See this rule for the conditional formatting:

oSheet = ThisDoc.Document.Sheets(1)

Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry

Dim oProperty = ThisDoc.ModelDocument.PropertySets.Item(4).Item("Db").Value

If UCase(oProperty) = "PAINTED" Then
	sText = "<StyleOverride Italic='True'><Property Document='model' " & _
	"PropertySet='User Defined Properties' Property='Db' " & _
	"FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='3'>Db</Property></StyleOverride>"
Else
	sText = "<StyleOverride Bold='True'><Property Document='model' " & _
	"PropertySet ='User Defined Properties' Property='Db' " & _
	"FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='3'>Db</Property></StyleOverride>"
End If

Dim oNote As GeneralNote
Dim oGenNotes = oSheet.DrawingNotes.GeneralNotes
For Each oNote In oSheet.DrawingNotes.GeneralNotes
	If UCase(oNote.Text) = "PAINTED" Or UCase(oNote.Text) = ("FURNER") Then oNote.Delete
Next

oGenNotes.AddFitted(oTG.CreatePoint2d(30, 5), sText)

 

 And you can use this simple 'helper' rule to get the formatting:

Dim oDoc As DrawingDocument
oDoc = ThisDoc.Document
Dim oSheet As Sheet = oDoc.ActiveSheet
Dim oNotes As GeneralNotes = oSheet.DrawingNotes.GeneralNotes

For Each oNote In oNotes
	'get formatted text
	InputBox("This is the formatted text for Textbox" & i, "ilogic", oNote.FormattedText)
	i = i + 1
Next

 

EESignature

Message 3 of 12

vvvxxvvv333
Enthusiast
Enthusiast

Thanks a lot for your reply and trying to help. But your rule defines what the font should be when placed, depending on the condition, but it does not change automatically if you change the parameter in the part

0 Likes
Message 4 of 12

robertast
Collaborator
Collaborator

The idea is very good. @johnsonshiue  @CGBenner     Could you ask the team if this can be done in Inventor?

Message 5 of 12

CGBenner
Community Manager
Community Manager

@robertast 

You can share your idea HERE, and ask the Community to vote for it if they agree.  Thanks!

Did you find a post helpful? Then feel free to give likes to these posts!
Did your question get successfully answered? Then just click on the 'Accept solution' button.  Thanks and Enjoy!


Chris Benner
Community Manager

0 Likes
Message 6 of 12

robertast
Collaborator
Collaborator

the question was to ask the team if this can be done in 2023.3 or if there is no such possibility at all

Message 7 of 12

Curtis_Waguespack
Consultant
Consultant

Hi @robertast 

 

There is no update in this behavior in Inventor Inventor 2023 compared to Inventor 2022 or previous.

 

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

EESignature

0 Likes
Message 8 of 12

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @vvvxxvvv333 

 

To get the drawing to update automatically when the model property is updated you could do something like what is shown below.

 

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

 

 

 

1. Update the rule in the part model:

 

iProperties.Value("Custom", "Db") = Ds
iLogicVb.UpdateWhenDone = True

oDrawDoc = ThisApplication.Documents.Open(ThisDoc.ChangeExtension(".idw"), True)

Dim DrawingUserParams As UserParameters
DrawingUserParams = oDrawDoc.Parameters.UserParameters
DrawingUserParams.Item("Parmeter_Db").Value = Ds

Thisdoc.Document.Activate

 

 

2. add a parameter to the drawing:

 

Curtis_Waguespack_0-1681762338711.png

 

 

3. Update the drawing rule:

 

oTrigger = Parmeter_Db
oSheet = ThisDoc.Document.Sheets(1)

Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry

Dim oProperty = ThisDoc.ModelDocument.PropertySets.Item(4).Item("Db").Value

If UCase(oProperty) = "PAINTED" Then
	sText = "<StyleOverride Italic='True'><Property Document='model' " & _
	"PropertySet='User Defined Properties' Property='Db' " & _
	"FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='3'>Db</Property></StyleOverride>"
Else
	sText = "<StyleOverride Bold='True'><Property Document='model' " & _
	"PropertySet ='User Defined Properties' Property='Db' " & _
	"FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='3'>Db</Property></StyleOverride>"
End If

Dim oNote As GeneralNote
Dim oGenNotes = oSheet.DrawingNotes.GeneralNotes
For Each oNote In oSheet.DrawingNotes.GeneralNotes
	If UCase(oNote.Text) = "PAINTED" Or UCase(oNote.Text) = ("FURNER") Then oNote.Delete
Next

oGenNotes.AddFitted(oTG.CreatePoint2d(30, 5), sText)

 

 

EESignature

Message 9 of 12

Curtis_Waguespack
Consultant
Consultant
Accepted solution

@vvvxxvvv333 

 

Another approach would be to delete the drawing rule and just have all of the code in the part model rule:

 

iProperties.Value("Custom", "Db") = Ds
iLogicVb.UpdateWhenDone = True

Dim oDrawDoc As DrawingDocument = ThisApplication.Documents.Open(ThisDoc.ChangeExtension(".idw"), True)

oSheet = oDrawDoc.Sheets.Item(1)

Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry

Dim oProperty = ThisDoc.Document.PropertySets.Item(4).Item("Db").Value

If UCase(oProperty) = "PAINTED" Then
	sText = "<StyleOverride Italic='True'><Property Document='model' " & _
	"PropertySet='User Defined Properties' Property='Db' " & _
	"FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='3'>Db</Property></StyleOverride>"
Else
	sText = "<StyleOverride Bold='True'><Property Document='model' " & _
	"PropertySet ='User Defined Properties' Property='Db' " & _
	"FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='3'>Db</Property></StyleOverride>"
End If

Dim oNote As GeneralNote
Dim oGenNotes = oSheet.DrawingNotes.GeneralNotes
For Each oNote In oSheet.DrawingNotes.GeneralNotes
	If UCase(oNote.Text) = "PAINTED" Or UCase(oNote.Text) = ("FURNER") Then oNote.Delete
Next

oGenNotes.AddFitted(oTG.CreatePoint2d(30, 5), sText)


Thisdoc.Document.Activate

 

EESignature

Message 10 of 12

vvvxxvvv333
Enthusiast
Enthusiast

You are a wizard 👍👍👍 
Maybe ShowTextBorder can also be applied this way?

 

I also thought about putting all the formatting text into one more parameter. But I didn't figure out how to use it.

 

iProperties.Value("Custom", "Db") = Ds


If Ds= Painted  Then
  iProperties.Value("Custom", "Dg") ="<StyleOverride Italic='True'><Property Document='model' " & _
	"PropertySet ='User Defined Properties' Property='Db' " & _
	"FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='3'>Db</Property></StyleOverride>"
Else

  iProperties.Value("Custom", "Dg") ="<StyleOverride Bold='True'><Property Document='model' " & _
	"PropertySet ='User Defined Properties' Property='Db' " & _
	"FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='3'>Db</Property></StyleOverride>"

End If

iLogicVb.UpdateWhenDone = True
0 Likes
Message 11 of 12

robertast
Collaborator
Collaborator
Accepted solution

There is another option through the trigger.

tiger2.jpg

Message 12 of 12

robertast
Collaborator
Collaborator

You can also try with "Rule Format"

 

Dim invApp As Inventor.Application
    invApp = ThisApplication
    Dim oDrawDoc As Document
    oDrawDoc = invApp.ActiveEditDocument
    oSheet = ActiveSheet.Sheet 
	Dim oGeneralNote As GeneralNote
        For Each oGeneralNote In oSheet.DrawingNotes.GeneralNotes
           oGeneralNote.ToString 
		   
	Dim oText As String
    	oText = oGeneralNote.Text
		 
		 If oText = "Furner" Then		 
			 
			 	Dim oFormattedText As String
    			oFormattedText = "<StyleOverride Bold='True'>" & oText & "</StyleOverride>"
	 			oGeneralNote.FormattedText = oFormattedText
				
				Else
					
				Dim oFormattedText As String
    			oFormattedText = "<StyleOverride Italic='True'>" & oText & "</StyleOverride>"
	 			oGeneralNote.FormattedText = oFormattedText
			End If
			

    	oGeneralNote .HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter
        Next