×
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!
  • Students Click Here

*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.

Students Click Here

Jobs

Format Font Macro

Format Font Macro

Format Font Macro

(OP)
I am working on this macro to format all text on a drawing.  Currently (as it is below) it gets all notes on sheet that are not in a view, and gets all notes on all sheets not in a view.  I need to get the text from views also, does anyone know what I am missing.  Reason I am trying this it to get our font type consistant in older drawings for a viewer we use on the macintosh systems here to view our dxf files.  Our doc control suggests we change all drawings to Helvetica font.  Easy enough for future work and for notes using Doc Settings but many are not covered.


Sub main()    
Set swApp = Application.SldWorks
Set Document = swApp.ActiveDoc
If Not Document Is Nothing Then
FileTyp = Document.GetType
If FileTyp = swDocDRAWING Then
SheetNames = Document.GetSheetNames
               
For i = 0 To Document.GetSheetCount - 1
Document.ActivateSheet (SheetNames(i))
Set View = Document.GetFirstView                    
Debug.Print "View = " + View.Name
Set Annotation = View.GetFirstAnnotation2           
While Not Annotation Is Nothing                     
If Annotation.GetType >= 1 Then
Set note = Annotation.GetSpecificAnnotation
noteval = note.GetText                      
textpoint = note.GetTextPoint
Debug.Print noteval
Set swAnn = Annotation
For j = 0 To swAnn.GetTextFormatCount - 1
Set swTextFormat = swAnn.GetTextFormat(j)
swTextFormat.Bold = True
swTextFormat.Italic = True
swTextFormat.TypeFaceName = "Helvetica"
bRet = swAnn.SetTextFormat(i, False, swTextFormat): Debug.Assert bRet
Next
Set Annotation = Annotation.GetNext2                
End If
Wend
Next i                                                     
If i > 0 Then                                           
Document.ActivateSheet (SheetNames(0))                 
End If                                                   
End If
Document.EditSheet
Document.ForceRebuild
Else
MsgBox "Current document is not a drawing."
End If
End Sub

RE: Format Font Macro

Do all a favor next time and use the "[code]" tag to separate your code.

You get the first view (which is the sheet itself) using

CODE

Set View = Document.GetFirstView

You don't have anything that gets the next view.  You probably want to cycle through all the views.  try a loop like this:

CODE

on error Resume Next
Do while not View is Nothing
   'nest your annotation change loop in here
   Set View = View.GetNextView
Loop

You may need yet another loop to cycle through the sheets if there are multiple sheets.

"When everyone is thinking alike, no one is thinking very much." --Eckhard Schwarz (1930--2004)
http://www.EsoxRepublic.com

RE: Format Font Macro

(OP)
Will do on the Code thangy, thanks for the info, I noticed that it was getting sheet 1 for the view but it was driving me batty (no pun towards your gifs).


I will try the code as you suggest, I really only need to access views on the first sheet, the remaining sheets contain no drawing views.


Thanks tick

RE: Format Font Macro

(OP)
Thanks for the help there Tick, I have it working now.  I guess that brings me to my second question, I didn't see a second question coming either.  At the end of this macro after it updates all annotations of all types in all views on all sheets to use Helvetica font, I want to change the User Preferences for all types of annotations to be Helvetica Font, so that if a user opens the drawing, runs the macro and then adds a note using defaults it will be Helvetica.  I am having a hard time finding a good example of changing user Preferences for font type.  Any Ideas???  I am able to retrieve it ok but I can't seem to properly word it to change.

RE: Format Font Macro

ModelDoc2.GetUserPreferenceTextFormat
ModelDoc2.SetUserPreferenceTextFormat

Note that you have a new object to deal with, a sldworks.TextFormat object.

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