BatchFile text size example

BatchFile text size example

Anonymous
Not applicable
297 Views
5 Replies
Message 1 of 6

BatchFile text size example

Anonymous
Not applicable
'With help from one and all I got a Batch file going. This
'one gets a Dir and new textsize from the user, then modifys the text,
'and resaves each dwg. I did 80 dwg's with it. I got pretty interested

'in batch files doing 'this. If anyone has any other nice batch files
'kicking around I would enjoy to receive them here or at my own e-mail
'Thanks all, and good luck! jim kitts
'Paste this into a module, then 'vbarun' at the command line
'
Dim TextSize As String 'load in 'SetCadBatch()
'TextSize used in SizeTxt()
Sub SetCadBatch()
'Ck if a live ACADDoc exists or make one
'get data from input boxs and trap errors
'jimbo\3:00 pm 3/6/00
'C:\JimJunk\Fundy4\X2 'my Fundy Park test file
'if user killed all dwg's add
'a blank to prevent an error
If Application.Documents.Count = 0 Then
Dim docObjNew As AcadDocument
Set docObjNew = Application.Documents.Add
End If
'at least one dwg is loaded
'so chose a drawing file
Dim dwgName As String
Dim msg As String: Dim title As String
msg = "Where is the Batch Directory?"
title = "Give it to me, baby!"
Dim inDir As String
inDir = InputBox(msg, title)
'check for a cancel
If inDir = "" Then
Exit Sub
End If
'ck if file exists if not, then exit
Dim tmp As String
temp = Dir$(inDir & "\*.dwg")
If temp = "" Then
MsgBox "Ain't no dwg here!"
Exit Sub
End If
msg = "What size do you want your text?"
title = "New Text Size"
TextSize = InputBox(msg, title) 'Dim in Declare
If TextSize = "" Then
Exit Sub 'trap cancel
End If
If Not IsNumeric(TextSize) Then 'trap text
MsgBox "Gotta give a number..."
Exit Sub
End If '
'loop through the files:
Dim filenom As String
filenom = Dir$(inDir & "\*.dwg")
Do While filenom <> ""
Dim WholeFile As String
WholeFile = inDir & "\" & filenom
'do somthin next
DoEvents
ThisDrawing.Application.Documents.Open WholeFile
DoEvents
Call SizeTxt 'reach out for the main routine
ThisDrawing.Close (True) ' gives a save
DoEvents
'end do somethin part
'set tmp to loop through again
filenom = Dir$
Loop
End Sub
'
Private Sub SizeTxt()
Dim elem As Object
Dim found As Boolean
' this is from the Acad examples
'Cycle through the entities in the ModelSpace
For Each elem In ThisDrawing.ModelSpace
With elem
If (.EntityName = "AcDbText") Or (.EntityName = "AcDbMText") Then
' Change the height of the text entity
.Height = TextSize '0.5 'dim in declarations
.Update
found = True
End If
End With
Set elem = Nothing
Next elem
' If we didn't find text, notify user
If Not found Then
MsgBox "No text found in ModelSpace.", vbInformation
End If
End Sub
'done for now, jim kitts
0 Likes
298 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Here is an alternative way by using ObjectDBX via axdb15.dll.

I runs really quick!

' Written by Jimmy B 2000-03-08
' Runs in AutoCAD 2000 with axdb15.dll
' Example of batch for changing text height on all drawings in a directory.

Private Sub setTextHeight()
Set objDbx = GetInterfaceObject("ObjectDBX.AxDbDocument")
Dim inDir As String
Dim elem As Object
Dim filenom As String
Dim WholeFile As String
Dim newHeight As Double
inDir = "c:\test"
filenom = Dir$(inDir & "\*.dwg")
newHeight = 3#
Do While filenom <> ""
WholeFile = inDir & "\" & filenom
objDbx.Open WholeFile
For Each elem In objDbx.ModelSpace
With elem
If ((TypeName(elem) = "IAcadText") Or (TypeName(elem) = "IAcadMText")) Then
.Height = newHeight
End If
End With
Next elem
For Each elem In objDbx.PaperSpace
With elem
If ((TypeName(elem) = "IAcadText") Or (TypeName(elem) = "IAcadMText")) Then
.Height = newHeight
End If
End With
Next elem
Set elem = Nothing
objDbx.SaveAs WholeFile
filenom = Dir$
Loop
End Sub

--
Best regards: Jimmy B
CAD coordinator at Emtunga International AB
www.emtunga.com
0 Likes
Message 3 of 6

Anonymous
Not applicable
Nice example.

Something you might consider that will speed this up: do the update after
looping through all of the entities. As I understand it, update is the same
thing as a regen. If you do it once when you're all done processing then
that's all it takes; one regen of the entire drawing instead of regen each
object as you go along.

Just a suggestion.

Mike

"Ruth Mitchell or Jim Kitts" wrote in message
news:38C52501.429F75F8@nbnet.nb.ca...
> 'With help from one and all I got a Batch file going. This
> 'one gets a Dir and new textsize from the user, then modifys the text,
> 'and resaves each dwg. I did 80 dwg's with it. I got pretty interested
>
> 'in batch files doing 'this. If anyone has any other nice batch files
> 'kicking around I would enjoy to receive them here or at my own e-mail
> 'Thanks all, and good luck! jim kitts
> 'Paste this into a module, then 'vbarun' at the command line
> '
> Dim TextSize As String 'load in 'SetCadBatch()
> 'TextSize used in SizeTxt()
> Sub SetCadBatch()
> 'Ck if a live ACADDoc exists or make one
> 'get data from input boxs and trap errors
> 'jimbo\3:00 pm 3/6/00
> 'C:\JimJunk\Fundy4\X2 'my Fundy Park test file
> 'if user killed all dwg's add
> 'a blank to prevent an error
> If Application.Documents.Count = 0 Then
> Dim docObjNew As AcadDocument
> Set docObjNew = Application.Documents.Add
> End If
> 'at least one dwg is loaded
> 'so chose a drawing file
> Dim dwgName As String
> Dim msg As String: Dim title As String
> msg = "Where is the Batch Directory?"
> title = "Give it to me, baby!"
> Dim inDir As String
> inDir = InputBox(msg, title)
> 'check for a cancel
> If inDir = "" Then
> Exit Sub
> End If
> 'ck if file exists if not, then exit
> Dim tmp As String
> temp = Dir$(inDir & "\*.dwg")
> If temp = "" Then
> MsgBox "Ain't no dwg here!"
> Exit Sub
> End If
> msg = "What size do you want your text?"
> title = "New Text Size"
> TextSize = InputBox(msg, title) 'Dim in Declare
> If TextSize = "" Then
> Exit Sub 'trap cancel
> End If
> If Not IsNumeric(TextSize) Then 'trap text
> MsgBox "Gotta give a number..."
> Exit Sub
> End If '
> 'loop through the files:
> Dim filenom As String
> filenom = Dir$(inDir & "\*.dwg")
> Do While filenom <> ""
> Dim WholeFile As String
> WholeFile = inDir & "\" & filenom
> 'do somthin next
> DoEvents
> ThisDrawing.Application.Documents.Open WholeFile
> DoEvents
> Call SizeTxt 'reach out for the main routine
> ThisDrawing.Close (True) ' gives a save
> DoEvents
> 'end do somethin part
> 'set tmp to loop through again
> filenom = Dir$
> Loop
> End Sub
> '
> Private Sub SizeTxt()
> Dim elem As Object
> Dim found As Boolean
> ' this is from the Acad examples
> 'Cycle through the entities in the ModelSpace
> For Each elem In ThisDrawing.ModelSpace
> With elem
> If (.EntityName = "AcDbText") Or (.EntityName = "AcDbMText") Then
> ' Change the height of the text entity
> .Height = TextSize '0.5 'dim in declarations
> .Update
> found = True
> End If
> End With
> Set elem = Nothing
> Next elem
> ' If we didn't find text, notify user
> If Not found Then
> MsgBox "No text found in ModelSpace.", vbInformation
> End If
> End Sub
> 'done for now, jim kitts
>
>
>
0 Likes
Message 4 of 6

Anonymous
Not applicable
My guess is that no update or regen is needed at all since the drawing is closed and saved.

Anyway: "The Update method updates the display of a single object only. The Regen
method regenerates the entire drawing and recomputes the screen coordi-nates
and view resolution for all objects. It also reindexes the drawing
database for optimum display and object selection performance."

--
Best regards: Jimmy B
CAD coordinator at Emtunga International AB
www.emtunga.com
Michael Weaver skrev i diskussionsgruppsmeddelandet:8a5ou8$7vr11@adesknews2.autodesk.com...
> Nice example.
>
> Something you might consider that will speed this up: do the update after
> looping through all of the entities. As I understand it, update is the same
> thing as a regen. If you do it once when you're all done processing then
> that's all it takes; one regen of the entire drawing instead of regen each
> object as you go along.
>
> Just a suggestion.
>
> Mike
>
>
> "Ruth Mitchell or Jim Kitts" wrote in message
> news:38C52501.429F75F8@nbnet.nb.ca...
> > 'With help from one and all I got a Batch file going. This
> > 'one gets a Dir and new textsize from the user, then modifys the text,
> > 'and resaves each dwg. I did 80 dwg's with it. I got pretty interested
> >
> > 'in batch files doing 'this. If anyone has any other nice batch files
> > 'kicking around I would enjoy to receive them here or at my own e-mail
> > 'Thanks all, and good luck! jim kitts
> > 'Paste this into a module, then 'vbarun' at the command line
> > '
> > Dim TextSize As String 'load in 'SetCadBatch()
> > 'TextSize used in SizeTxt()
> > Sub SetCadBatch()
> > 'Ck if a live ACADDoc exists or make one
> > 'get data from input boxs and trap errors
> > 'jimbo\3:00 pm 3/6/00
> > 'C:\JimJunk\Fundy4\X2 'my Fundy Park test file
> > 'if user killed all dwg's add
> > 'a blank to prevent an error
> > If Application.Documents.Count = 0 Then
> > Dim docObjNew As AcadDocument
> > Set docObjNew = Application.Documents.Add
> > End If
> > 'at least one dwg is loaded
> > 'so chose a drawing file
> > Dim dwgName As String
> > Dim msg As String: Dim title As String
> > msg = "Where is the Batch Directory?"
> > title = "Give it to me, baby!"
> > Dim inDir As String
> > inDir = InputBox(msg, title)
> > 'check for a cancel
> > If inDir = "" Then
> > Exit Sub
> > End If
> > 'ck if file exists if not, then exit
> > Dim tmp As String
> > temp = Dir$(inDir & "\*.dwg")
> > If temp = "" Then
> > MsgBox "Ain't no dwg here!"
> > Exit Sub
> > End If
> > msg = "What size do you want your text?"
> > title = "New Text Size"
> > TextSize = InputBox(msg, title) 'Dim in Declare
> > If TextSize = "" Then
> > Exit Sub 'trap cancel
> > End If
> > If Not IsNumeric(TextSize) Then 'trap text
> > MsgBox "Gotta give a number..."
> > Exit Sub
> > End If '
> > 'loop through the files:
> > Dim filenom As String
> > filenom = Dir$(inDir & "\*.dwg")
> > Do While filenom <> ""
> > Dim WholeFile As String
> > WholeFile = inDir & "\" & filenom
> > 'do somthin next
> > DoEvents
> > ThisDrawing.Application.Documents.Open WholeFile
> > DoEvents
> > Call SizeTxt 'reach out for the main routine
> > ThisDrawing.Close (True) ' gives a save
> > DoEvents
> > 'end do somethin part
> > 'set tmp to loop through again
> > filenom = Dir$
> > Loop
> > End Sub
> > '
> > Private Sub SizeTxt()
> > Dim elem As Object
> > Dim found As Boolean
> > ' this is from the Acad examples
> > 'Cycle through the entities in the ModelSpace
> > For Each elem In ThisDrawing.ModelSpace
> > With elem
> > If (.EntityName = "AcDbText") Or (.EntityName = "AcDbMText") Then
> > ' Change the height of the text entity
> > .Height = TextSize '0.5 'dim in declarations
> > .Update
> > found = True
> > End If
> > End With
> > Set elem = Nothing
> > Next elem
> > ' If we didn't find text, notify user
> > If Not found Then
> > MsgBox "No text found in ModelSpace.", vbInformation
> > End If
> > End Sub
> > 'done for now, jim kitts
> >
> >
> >
>
>
0 Likes
Message 5 of 6

Anonymous
Not applicable
>"Jimmy B" wrote in message
news:8a5s78$7tl24@adesknews2.autodesk.com...
>My guess is that no update or regen is needed at all since the drawing is
closed and saved.

Good point.

>Anyway: "The Update method updates the display of a single object only. The
Regen
>method regenerates the entire drawing and recomputes the screen
coordi-nates
>and view resolution for all objects. It also reindexes the drawing
>database for optimum display and object selection performance."

Then what does application.update do?

>--
>Best regards: Jimmy B
>CAD coordinator at Emtunga International AB
>www.emtunga.com

--
==============================
Michael Weaver
Charles Bettisworth & Co.
mweaver@bettisworth.com
==============================
0 Likes
Message 6 of 6

Anonymous
Not applicable
Gee thanks. That is REAL fast. Mike Weaver tried to put me onto this before. I should
have listened a little more.

jim
0 Likes