Changing Block Attributes

Changing Block Attributes

Anonymous
Not applicable
239 Views
4 Replies
Message 1 of 5

Changing Block Attributes

Anonymous
Not applicable
I have 500+ drawings that I have to change two (2) to four (4) of the Title
Block attributes. So far I have been able to come up with the following
code (with the help of this newsgroup):

Public Sub T_TBChange()

Dim AttArray As Variant
Dim Obj As Object
Dim blkRef As AcadBlockReference
Dim BlockName As String
Dim returnString As String
Dim TPn As String
Dim TDes As String
Dim objWorksheet As Object
Dim objWorkBook As Object
If blnAll = False Then

For Each Obj In ThisDrawing.PaperSpace
If TypeOf Obj Is AcadBlockReference Then
Set blkRef = Obj

If blkRef.HasAttributes Then
AttArray = blkRef.GetAttributes
For I = LBound(AttArray) To UBound(AttArray)
' MsgBox AttArray(i).TagString
MsgBox returnString

If AttArray(I).TagString = "PB2" Then
AttArray(I).TextString = TPn
in VBA.


If AttArray(I).TagString = "A" Then
AttArray(I).TextString = TDes
Next I
End If
End If
Next
End If
End Sub

The problem that I am having the attribute TextString is going to be
changing in each drawing (along with the other two attributes, that I have
not yet defined in this code).

I need to be able to input these new TextString values (TPn and TDes) from
a input routine when the code runs.
For some reason - I have not been able to do this with my limited knowledge
in VBA.

Thanks in advance Robert Funk
0 Likes
240 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
Inline comments:

"Robert Funk" wrote in message
news:8D87882645738E7DB129F70E5FBEAFD4@in.WebX.maYIadrTaRb...
> I have 500+ drawings that I have to change two (2) to four (4) of the
Title
> Block attributes. So far I have been able to come up with the following
> code (with the help of this newsgroup):
>
'####################### Following line changed
> Public Sub T_TBChange(TPn as string, TDes as string, NewVal1 as string,
NewVal2 as string)
>
> Dim AttArray As Variant
> Dim Obj As Object
> Dim blkRef As AcadBlockReference
> Dim BlockName As String
> Dim returnString As String
'#################### the following two lines commented out
'Dim TPn As String
'Dim TDes As String
> Dim objWorksheet As Object
> Dim objWorkBook As Object
> If blnAll = False Then
>
> For Each Obj In ThisDrawing.PaperSpace
> If TypeOf Obj Is AcadBlockReference Then
> Set blkRef = Obj
>
> If blkRef.HasAttributes Then
> AttArray = blkRef.GetAttributes
> For I = LBound(AttArray) To UBound(AttArray)
> ' MsgBox AttArray(i).TagString
> MsgBox returnString
>
'###################### Following line added
if AttArray(i).TagString = "Target1" then
AttArray(i).TextString = NewVal1
'###################### Following line added
if AttArray(i).TagString = "Target2" then
AttArray(i).TextString = NewVal2
> If AttArray(I).TagString = "PB2" Then
> AttArray(I).TextString = TPn
> in VBA.
>
>
> If AttArray(I).TagString = "A" Then
> AttArray(I).TextString = TDes
> Next I
> End If
> End If
> Next
> End If
> End Sub
>

You might also want to consider using Select Case:

For I = LBound(AttArray) To UBound(AttArray)
Set AttObj = AttArray(i)
Select Case AttObj.TagString
Case is = "Target1"
AttObj.TextString = NewVal1
Case is = "Target2"
AttObj.TextString = NewVal2
Case is = "PB2"
AttObj.TextString = TPn
Case is = "A"
AttObj.TextString = TDes
End Select
Next I



snip...


Mike Weaver
0 Likes
Message 3 of 5

Anonymous
Not applicable
It seem that I am having trouble with my email at home so I will repost to the newsgroupe and you.



The ones that I will be doing will have one block to each layout and only

one of these blocks in the drawing, in the paper space layout.  The code

runs as expected when I have a string valve  "10004567" substituted for the

value of  TPn  and  an value of "B" in the for the second attribute (TDes

value) in the following lines:



   If AttArray(I).TagString = "PB2" Then AttArray(I).TextString = TPn

   If AttArray(I).TagString = "A" Then AttArray(I).TextString = TDes



I have tried to enter the text in a listbox by typing this as a number

(string value without the quotes) and then having the out put of the listbox set to a string value/s

to the variable/s of TPn and TDes in a second listbox.



---- Original Message -----

From: "Bernard Flavignard" <be.flavi@infonie.fr>

To: "Robert Funk" <bob_funk@prodigy.net>

Sent: Tuesday, May 29, 2001 10:42 AM

Subject: Re: Changing Block Attributes





> Robert,

>

> How many title block in a drawing, one for each drawing or ....

>

> Bernard

> ----- Original Message -----

> From: Robert Funk <bob_funk@prodigy.net>

> To: Bernard Flavignard <be.flavi@infonie.fr>

> Cc: Robert Funk <bob_funk@cooksonpm.com>

> Sent: Tuesday, May 29, 2001 7:23 PM

> Subject: Re: Changing Block Attributes

>

>

> > 95% of all the title blocks are the same.  The two attributes tags (PB2

&

> A)

> > are all the same in most of the blocks.  The current strings have

> different

> > information attached to the blocks.  The new information to be written

> into

> > the blocks will be different in each block.  I hop to put this in as the

> > code is running for each block.

> >

> > Drawing Attached.  Drawing format AutoCad MDT5 Service Pack 3.

> >

> >         Thanks for ypu response and HELP.

> >

> > ----- Original Message -----

> > From: "Bernard Flavignard" <be.flavi@infonie.fr>

> > To: "Robert Funk" <bob_funk@prodigy.net>

> > Sent: Tuesday, May 29, 2001 6:42 AM

> > Subject: Re: Changing Block Attributes

> >

> >

> > > Robert,

> > >

> > > Do you want the same new string for each block with tagstring = "PB2"

> > > Or do you want differents news strings

> > >

> > > Can you send me one of your drawing with your blocks

> > >

> > > Bernard

> > > ----- Original Message -----

> > > From: Robert Funk <bob_funk@prodigy.net>

> > > Newsgroups: autodesk.autocad.customization.vba

> > > Sent: Tuesday, May 29, 2001 2:20 PM

> > > Subject: Changing Block Attributes

> > >

> > >

> > > > I have 500+ drawings that I have to change two (2) to four (4) of

the

> > > Title

> > > > Block attributes.  So far I have been able to come up with the

> following

> > > > code (with the help of this newsgroup):

> > > >

> > > > Public Sub T_TBChange()

> > > >

> > > > Dim AttArray As Variant

> > > > Dim Obj As Object

> > > > Dim blkRef As AcadBlockReference

> > > > Dim BlockName As String

> > > > Dim returnString As String

> > > > Dim TPn As String

> > > > Dim TDes As String

> > > > Dim objWorksheet As Object

> > > > Dim objWorkBook As Object

> > > > If blnAll = False Then

> > > >

> > > >     For Each Obj In ThisDrawing.PaperSpace

> > > >         If TypeOf Obj Is AcadBlockReference Then

> > > >         Set blkRef = Obj

> > > >

> > > >             If blkRef.HasAttributes Then

> > > >             AttArray = blkRef.GetAttributes

> > > >                 For I = LBound(AttArray) To UBound(AttArray)

> > > > '               MsgBox AttArray(i).TagString

> > > >                 MsgBox returnString

> > > >

> > > >                     If AttArray(I).TagString = "PB2" Then

> > > > AttArray(I).TextString = TPn

> > > >                      in VBA.

> > > >

> > > >

> > > >                     If AttArray(I).TagString = "A" Then

> > > > AttArray(I).TextString = TDes

> > > >                 Next I

> > > >             End If

> > > >         End If

> > > >     Next

> > > > End If

> > > > End Sub

> > > >

> > > > The problem that I am having the attribute TextString is going to be

> > > > changing in each drawing (along with the other two attributes, that

I

> > have

> > > > not yet defined in this code).

> > > >

> > > > I need to be able to input these new TextString values  (TPn and

TDes)

> > > from

> > > > a input routine when the code runs.

> > > > For some reason - I have not been able to do this with my limited

> > > knowledge

> > > > in VBA.

> > > >

> > > > Thanks in advance Robert Funk

Mike Weaver wrote:

Inline comments:

"Robert Funk" <bob_funk@prodigy.net> wrote in message
news:8D87882645738E7DB129F70E5FBEAFD4@in.WebX.maYIadrTaRb...

I have 500+ drawings that I have to change two (2) to four (4) of the

Title

Block attributes.  So far I have been able to come up with the following
code (with the help of this newsgroup):


'####################### Following line changed

Public Sub T_TBChange(TPn as string, TDes as string, NewVal1 as string,

NewVal2 as string)

Dim AttArray As Variant
Dim Obj As Object
Dim blkRef As AcadBlockReference
Dim BlockName As String
Dim returnString As String

'#################### the following two lines commented out
'Dim TPn As String
'Dim TDes As String

Dim objWorksheet As Object
Dim objWorkBook As Object
If blnAll = False Then

For Each Obj In ThisDrawing.PaperSpace
If TypeOf Obj Is AcadBlockReference Then
Set blkRef = Obj

If blkRef.HasAttributes Then
AttArray = blkRef.GetAttributes
For I = LBound(AttArray) To UBound(AttArray)
' MsgBox AttArray(i).TagString
MsgBox returnString


'###################### Following line added
if AttArray(i).TagString = "Target1" then
AttArray(i).TextString = NewVal1
'###################### Following line added
if AttArray(i).TagString = "Target2" then
AttArray(i).TextString = NewVal2

                    If AttArray(I).TagString = "PB2" Then
AttArray(I).TextString = TPn
in VBA.


If AttArray(I).TagString = "A" Then
AttArray(I).TextString = TDes
Next I
End If
End If
Next
End If
End Sub



You might also want to consider using Select Case:

For I = LBound(AttArray) To UBound(AttArray)
Set AttObj = AttArray(i)
Select Case AttObj.TagString
Case is = "Target1"
AttObj.TextString = NewVal1
Case is = "Target2"
AttObj.TextString = NewVal2
Case is = "PB2"
AttObj.TextString = TPn
Case is = "A"
AttObj.TextString = TDes
End Select
Next I



snip...


Mike Weaver





0 Likes
Message 4 of 5

Anonymous
Not applicable
I am having trouble with my home email, so I did
not receive your response till today, when I came back to work. Thanks for
your help.  This is and the additional help I received will make changing
all the drawing title blocks an easier job.



One other question - Since I also have the part number (eight digit number
as 10004545) in the BOM block (for AutoCad Mechanical Desktop MDT5 w/service
pack 3) is their an easy way to automatically put this in the BOM and Part
list in the layout.  Most of the drawings will consist of only one model
(made up of only one part) and only one layout in the drawing.

I will be inserting an new part list format into each drawing, so I thought
while I am inserting it, there would be a way of getting some of the information
that I would be imputing for the title block.



           T H A N K S   In Advance.





Mike Weaver wrote:

Inline comments:

"Robert Funk" <bob_funk@prodigy.net> wrote in message
news:8D87882645738E7DB129F70E5FBEAFD4@in.WebX.maYIadrTaRb...

I have 500+ drawings that I have to change two (2) to four (4) of the

Title

Block attributes.  So far I have been able to come up with the following
code (with the help of this newsgroup):


'####################### Following line changed

Public Sub T_TBChange(TPn as string, TDes as string, NewVal1 as string,

NewVal2 as string)

Dim AttArray As Variant
Dim Obj As Object
Dim blkRef As AcadBlockReference
Dim BlockName As String
Dim returnString As String

'#################### the following two lines commented out
'Dim TPn As String
'Dim TDes As String

Dim objWorksheet As Object
Dim objWorkBook As Object
If blnAll = False Then

For Each Obj In ThisDrawing.PaperSpace
If TypeOf Obj Is AcadBlockReference Then
Set blkRef = Obj

If blkRef.HasAttributes Then
AttArray = blkRef.GetAttributes
For I = LBound(AttArray) To UBound(AttArray)
' MsgBox AttArray(i).TagString
MsgBox returnString


'###################### Following line added
if AttArray(i).TagString = "Target1" then
AttArray(i).TextString = NewVal1
'###################### Following line added
if AttArray(i).TagString = "Target2" then
AttArray(i).TextString = NewVal2

                    If AttArray(I).TagString = "PB2" Then
AttArray(I).TextString = TPn
in VBA.


If AttArray(I).TagString = "A" Then
AttArray(I).TextString = TDes
Next I
End If
End If
Next
End If
End Sub



You might also want to consider using Select Case:

For I = LBound(AttArray) To UBound(AttArray)
Set AttObj = AttArray(i)
Select Case AttObj.TagString
Case is = "Target1"
AttObj.TextString = NewVal1
Case is = "Target2"
AttObj.TextString = NewVal2
Case is = "PB2"
AttObj.TextString = TPn
Case is = "A"
AttObj.TextString = TDes
End Select
Next I



snip...


Mike Weaver





0 Likes
Message 5 of 5

Anonymous
Not applicable
Bob,

I don't know very much about MDT, but if the bom is
a block with attributes you should be able to modify these attributes the same
way you would with the titble block.

 

Mike

 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I
am having trouble with my home email, so I did not receive your response till
today, when I came back to work. Thanks for your help.  This is and the
additional help I received will make changing all the drawing title blocks an
easier job.

One other question - Since I also have the part number
(eight digit number as 10004545) in the BOM block (for AutoCad Mechanical
Desktop MDT5 w/service pack 3) is their an easy way to automatically put this
in the BOM and Part list in the layout.  Most of the drawings will
consist of only one model (made up of only one part) and only one layout in
the drawing.
I will be inserting an new part list format into each drawing,
so I thought while I am inserting it, there would be a way of getting some of
the information that I would be imputing for the title
block.

           T H A N K S
  In Advance.


@mike Weaver wrote:


type="cite">
Inline comments:

"Robert Funk" <bob_funk@prodigy.net> wrote in message
news:8D87882645738E7DB129F70E5FBEAFD4@in.WebX.maYIadrTaRb...

I have 500+ drawings that I have to change two (2) to four (4) of the
Title

Block attributes.  So far I have been able to come up with the following
code (with the help of this newsgroup):

'####################### Following line changed

Public Sub T_TBChange(TPn as string, TDes as string, NewVal1 as string,
NewVal2 as string)

Dim AttArray As Variant
Dim Obj As Object
Dim blkRef As AcadBlockReference
Dim BlockName As String
Dim returnString As String
'#################### the following two lines commented out
'Dim TPn As String
'Dim TDes As String

Dim objWorksheet As Object
Dim objWorkBook As Object
If blnAll = False Then

For Each Obj In ThisDrawing.PaperSpace
If TypeOf Obj Is AcadBlockReference Then
Set blkRef = Obj

If blkRef.HasAttributes Then
AttArray = blkRef.GetAttributes
For I = LBound(AttArray) To UBound(AttArray)
' MsgBox AttArray(i).TagString
MsgBox returnString

'###################### Following line added
if AttArray(i).TagString = "Target1" then
AttArray(i).TextString = NewVal1
'###################### Following line added
if AttArray(i).TagString = "Target2" then
AttArray(i).TextString = NewVal2

                    If AttArray(I).TagString = "PB2" Then
AttArray(I).TextString = TPn
in VBA.


If AttArray(I).TagString = "A" Then
AttArray(I).TextString = TDes
Next I
End If
End If
Next
End If
End Sub


You might also want to consider using Select Case:

For I = LBound(AttArray) To UBound(AttArray)
Set AttObj = AttArray(i)
Select Case AttObj.TagString
Case is = "Target1"
AttObj.TextString = NewVal1
Case is = "Target2"
AttObj.TextString = NewVal2
Case is = "PB2"
AttObj.TextString = TPn
Case is = "A"
AttObj.TextString = TDes
End Select
Next I



snip...


Mike Weaver



0 Likes