INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Set text color Drafting Macro

Set text color Drafting Macro

(OP)
Hello all,

I'm trying to set the red color on a text I have added with the following code taken from VBA help:

Property Color( ) As long

Returns or sets the color of the drawing text.
Example:
This example sets the Color type of the MyText drawing text to red
redCol =-16776961 'Encoded RGBA color within long integer (R=255 G=0 B=0 A=255)
MyText.Color = redCol

Code I'm trying:

MyText.SetFontSize 0, 0, 20
redCol = -16776961
MyText.Color = redCol 'ERROR

SetFontSize works perfectly but the line for the colour doesn't...

Another thing I've tried is this code, based on a search I have done in the forum, but doesn't work neither:

MyText.visProperties1.SetRealColor 255, 0, 0, 1

Any ideas?

(I'm coding on VBA)



RE: Set text color Drafting Macro

Hi

CODE --> CATScript

' ==============================================================
' Purpose: This macro will change the color of all text in drawing to red
' Usage:   1 - Works in an active catdrawing
'          2 - Run macro 
' Author: ferdo (Disclaimer: You use this code at your own risk) 
' ===============================================================

Language="VBSCRIPT"

Sub CATMain()

' Set the CATIA popup file alerts to False
' It prevents to stop the macro at each alert during its execution

CATIA.DisplayFileAlerts = False
Set oDrwDocument = CATIA.ActiveDocument

' Retrieve the drawing document's view collection
Set oDrwView = oDrwDocument.Sheets.Item(1).views
Dim drawingDocument1 As Document
Set drawingDocument1 = CATIA.ActiveDocument
Dim selection1 As Selection
Set selection1 = drawingDocument1.Selection

selection1.Search "CATDrwSearch.DrwText.TextString=*,all"

'For each view search text
For i = 2 To oDrwView.Count

'Scan all the Texts of the Views
For numtxt = 1 To oDrwView.Item(i).Texts.Count
Set CurrentView = oDrwView.Item(i)

'Change the color of the text in RED
Set Drwselect = CATIA.ActiveDocument.Selection
Drwselect.Add oDrwView.Item(i).Texts.Item(numtxt)
Drwselect.VisProperties.SetRealColor 255, 0, 0, 0

Next
Next

End Sub 

Regards
Fernando

https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU

RE: Set text color Drafting Macro

(OP)
Thank you for answering but I have the same problem...

What I'm trying to do is put in red only the word I've just written.


Sub InsertText()

Set MyDrawingDoc = CATIA.ActiveDocument
Set MyDrawingSheets = MyDrawingDoc.Sheets
Set MyDrawingSheet = MyDrawingSheets.ActiveSheet

Dim MyDrawingViews As DrawingViews
Set MyDrawingViews = MyDrawingSheet.Views

Dim InsertText As String

InsertText = InputBox("Insert Text")

'Set myText.... As DrawingText - adding texts
Set myText = MyDrawingViews.ActiveView.Texts.Add(InsertText, 33, 75)

myText.SetFontSize 0, 0, 20
myText.VisProperties.SetRealColor 255, 0, 0, 0 'ERROR

End Sub

RE: Set text color Drafting Macro

Or, if you don't want to use search

CODE --> CATScript

Sub CATMain()

Set MyDrawingDoc = CATIA.ActiveDocument
Set MyDrawingSheets = MyDrawingDoc.Sheets
Set MyDrawingSheet = MyDrawingSheets.ActiveSheet

Dim MyDrawingViews As DrawingViews
Set MyDrawingViews = MyDrawingSheet.Views

Dim InsertText As String

InsertText = InputBox("Insert Text")

'Set myText.... As DrawingText - adding texts
Set myText = MyDrawingViews.ActiveView.Texts.Add(InsertText, 33, 75)
myText.SetFontSize 0, 0, 20

           '~ 'Change the color of the text in RED
                Set Drwselect = CATIA.ActiveDocument.Selection
                           DrwSelect.Add myText
                  DrwSelect.VisProperties.SetRealColor 255, 0, 0, 0

End Sub 

Regards
Fernando

https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU

RE: Set text color Drafting Macro

(OP)
Great, much better!

I didn't find the way of putting the variable in the following code...

selection1.Search "CATDrwSearch.DrwText.TextString= ____ "

Actually, I have to put a string followed by the variable, anyway... now works perfectly.

Thank you very much Berto.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close