Jump to content

Add Text VBA


sanderson

Recommended Posts

Hi:

 

I am using SolidWorks 2DEditor, and need to add some text from code to the lower-right corner of the drawing. The snag seems to be in obtaining the system variables EXTMIN and EXTMAX.

 

Any thoughts??

 

Thanks in advance for the help!

 

 
Sub AddFooter()
   Dim txtfooterString As String
   txtfooterString = "n:\temp\footerstring.txt"
   Dim footerString As String
   Open txtfooterString For Input As #1
   Do While Not EOF(1)
       Line Input #1, footerString
   
   Loop
   
   Close #1
   
   MsgBox ("footerString: " & footerString)
   
   Dim minExt As Object
   Dim maxExt As Object
   Set minExt = doc.GetVariable("EXTMIN")
   Set maxExt = doc.GetVariable("EXTMAX")
   
   MsgBox (CStr(maxExt) & ", " & CStr(minExt))
          
   Dim lr(0 To 1) As Double
   lr(0) = maxExt(0)
   lr(1) = minExt(1)
   
   Dim height As Double
   height = 0.1
   
   Dim textObj As Text
   Set textObj = doc.AddText(footerString, lr, height)
   
   textObj.Update
       
End Sub

Link to comment
Share on other sites

 
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub Main()
   Dim doc As DWGeditor.Document
   Set doc = DWGeditor.ActiveDocument
   Sleep (5)
   
   AddFooter
   
   Sleep (5)
   
   Dim lyt As Layout
   Set lyt = doc.ActiveLayout
   lyt.PlotType = vicExtents
   lyt.PlotRotation = vic90degrees
   lyt.StyleSheet = "monochrome.ctb"
   lyt.PaperUnits = vicInches
   lyt.StandardScale = vicToFit
   lyt.ScaleLineweights = False
   lyt.CenterPlot = True
   doc.Regen
   Set lyt = Nothing
   doc.PrintDrawing
End Sub
Sub AddFooter()
   Dim doc As DWGeditor.Document
   Set doc = DWGeditor.ActiveDocument
   
   Dim txtfooterString As String
   txtfooterString = "n:\temp\footerstring.txt"
   Dim footerString As String
   Open txtfooterString For Input As #1
   Do While Not EOF(1)
       Line Input #1, footerString
   
   Loop
   
   Close #1
   
   Debug.Print ("footerString: " & footerString)
   
   Dim minExt As DWGeditor.Point
   Dim maxExt As DWGeditor.Point
   Set minExt = doc.GetVariable("EXTMIN")
   Set maxExt = doc.GetVariable("EXTMAX")
   
   Dim sc As Double
   sc = doc.GetVariable("DIMSCALE")
    
   Dim ip As Object
   Set ip = Library.CreatePoint(0.987 * maxExt.x, minExt.y, 0)
   
   Dim height As Double
   height = 0.0625 * sc
   
   Dim textObj As DWGeditor.Text
   Set textObj = doc.ModelSpace.AddText(footerString, ip, height)
   textObj.HorizontalAlignment = vicHorizontalAlignmentRight
   
   textObj.Update
       
End Sub

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...