Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations MintJulep on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format Font Macro 1

Status
Not open for further replies.

aamoroso

Mechanical
Mar 5, 2003
432
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
 
Replies continue below

Recommended for you

Do all a favor next time and use the [ignore]"
Code:
"[/ignore] 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.

[bat]"When everyone is thinking alike, no one is thinking very much." --Eckhard Schwarz (1930--2004)[bat]
 
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
 
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.
 
ModelDoc2.GetUserPreferenceTextFormat
ModelDoc2.SetUserPreferenceTextFormat

Note that you have a new object to deal with, a sldworks.TextFormat object.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor