Modifying block attributes without using GetAttributes

Modifying block attributes without using GetAttributes

Anonymous
Not applicable
745 Views
8 Replies
Message 1 of 9

Modifying block attributes without using GetAttributes

Anonymous
Not applicable
Hi.

I am trying to modify the attributes of a specific block inserted into my
drawing.

I have specific reasons for not wanting to loop through the modelspace for
the correct block-element, and not using GetAttributes to receive an array
of all attributes and so on.(I am using OLE Automation from an external
application to remotly change blockattributes inside a drawing),

So my question is; Is it possible to modify attributes using the syntax
below?



ThisDrawing.Blocks(1).Item(1).TextString = "TEST"



This syntax works, I am able to write "TEST" into the specific items
TextString. But, the drawing is not updated.

Also, If I edit the drawing and change the blockattribute-values using
DDEDIT, I cannot read these changes from VBA using
ThisDrawing.Blocks(1).Item(1).TextString. It will only display blanks.


Am I missing something here? Is the blockattribute-values accessed through
DDEDIT different than the ones accessed through
ThisDrawing.Blocks(1).Item(1).TextString?



regards,
Bjørn Holm
DASH Software AS
Norway
0 Likes
746 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable
"Bjørn Holm " <=?UTF-8?Q?Bj=C3=B8rn_Holm_?=> wrote
in message news:6033222@discussion.autodesk.com...
Hi.

"I am trying to modify the attributes of a specific block inserted into my
drawing.

I have specific reasons for not wanting to loop through the modelspace for
the correct block-element, and not using GetAttributes to receive an array
of all attributes and so on (I am using OLE Automation from an external
application to remotly change blockattributes inside a drawing),"

theres no reason you cant' work with the acad api as it's designed that I
know of.
if you're working in the editor you can use filtered selection sets in lieu
of iterating mspace/pspace

So my question is; Is it possible to modify attributes using the syntax
below?
ThisDrawing.Blocks(1).Item(1).TextString = "TEST"
This syntax works, I am able to write "TEST" into the specific items
TextString. But, the drawing is not updated.

By some miracle the second item in your block table had a .TextString
property! very lucky if that didn't error.
also even if that would work(which in general it won't) if you modify an
attribute in a block definition it won't affect block references in the dwg.
hth
mark
0 Likes
Message 3 of 9

Anonymous
Not applicable
Firstly, why you decided using external automation is the reason you do not
want to use GetAttributes()?

Secondly, do you want to change Block definition, or do you want to change
block reference?

ThisDrawing.Blocks refers to block definitions in the drawing.

Thirdly, ThisDrawing.Blocks(i).Item(j) could be anything that is part of the
block definition, such as line, circle and/or an attribute. Unless you are
100% sure that the block referred by Blocks(i) contains only attributes,
this cade

ThisDrawing.Blocks(1).Item(1).TextString = "TEST"

is simply not useful.



"Bjørn Holm " wrote in message
news:6033222@discussion.autodesk.com...
Hi.

I am trying to modify the attributes of a specific block inserted into my
drawing.

I have specific reasons for not wanting to loop through the modelspace for
the correct block-element, and not using GetAttributes to receive an array
of all attributes and so on.(I am using OLE Automation from an external
application to remotly change blockattributes inside a drawing),

So my question is; Is it possible to modify attributes using the syntax
below?



ThisDrawing.Blocks(1).Item(1).TextString = "TEST"



This syntax works, I am able to write "TEST" into the specific items
TextString. But, the drawing is not updated.

Also, If I edit the drawing and change the blockattribute-values using
DDEDIT, I cannot read these changes from VBA using
ThisDrawing.Blocks(1).Item(1).TextString. It will only display blanks.


Am I missing something here? Is the blockattribute-values accessed through
DDEDIT different than the ones accessed through
ThisDrawing.Blocks(1).Item(1).TextString?



regards,
Bjørn Holm
DASH Software AS
Norway
0 Likes
Message 4 of 9

Anonymous
Not applicable
Hi Mark.

I have one specific block that I insert in all drawings. This block is
static and never changes, so all blockitems are also static, both in
properties and order.
I understand that I am confusing blockdefinition with blockreferance, and
that this is the problem.

What I actually trying to do is figuring out the correct syntax for an
OLE-string that I need to send from my application(made in Clarion for
Windows(by Softvelocity)) to AutoCad.

This is the syntax for communicating through OLE in Clarion for Windows:

?AcadOLEObject{Prop:Create} = "AutoCAD.Application"
?AcadOLEObject{Prop:Ole} = "ThisDrawing.Blocks(1).Item(1).TextString =
"TEST""


As you can see I have no possibillity to loop through Modelspace finding the
correct block, running GetAttributes and so on, as my OLE-strings are
executed one at a time.

?AcadObject{Prop:Ole} = "For Each Elem In ThisDrawing.ModelSpace"
?AcadObject{Prop:Ole} = "If StrComp(Elem.EntityName, "AcDbBlockReference",
1) = 0 Then"
?AcadObject{Prop:Ole} = "Array1 = Elem.GetAttributes"
?AcadObject{Prop:Ole} = "End If"
?AcadObject{Prop:Ole} = "Next Elem"

This simply won't work, so I need to access the correct blockitem through
one line of code.


regards,
Bjørn Holm
DASH Software AS
Norway



"MP" wrote in message
news:6033318@discussion.autodesk.com...
"Bjørn Holm " <=?UTF-8?Q?Bj=C3=B8rn_Holm_?=> wrote
in message news:6033222@discussion.autodesk.com...
Hi.

"I am trying to modify the attributes of a specific block inserted into my
drawing.

I have specific reasons for not wanting to loop through the modelspace for
the correct block-element, and not using GetAttributes to receive an array
of all attributes and so on (I am using OLE Automation from an external
application to remotly change blockattributes inside a drawing),"

theres no reason you cant' work with the acad api as it's designed that I
know of.
if you're working in the editor you can use filtered selection sets in lieu
of iterating mspace/pspace

So my question is; Is it possible to modify attributes using the syntax
below?
ThisDrawing.Blocks(1).Item(1).TextString = "TEST"
This syntax works, I am able to write "TEST" into the specific items
TextString. But, the drawing is not updated.

By some miracle the second item in your block table had a .TextString
property! very lucky if that didn't error.
also even if that would work(which in general it won't) if you modify an
attribute in a block definition it won't affect block references in the dwg.
hth
mark
0 Likes
Message 5 of 9

Anonymous
Not applicable
Hi Norman, thanks for your reply.
I am a 100% sure that I am accessing the correct property in the correct
item, as the block is static and never changes.
Also, see my reply to Mark for a more detailed explanation on what it is I
am trying to accomplish.

regards,
Bjørn Holm
DASH Software AS
Norway

"Norman Yuan" wrote in message
news:6033324@discussion.autodesk.com...
Firstly, why you decided using external automation is the reason you do not
want to use GetAttributes()?

Secondly, do you want to change Block definition, or do you want to change
block reference?

ThisDrawing.Blocks refers to block definitions in the drawing.

Thirdly, ThisDrawing.Blocks(i).Item(j) could be anything that is part of the
block definition, such as line, circle and/or an attribute. Unless you are
100% sure that the block referred by Blocks(i) contains only attributes,
this cade

ThisDrawing.Blocks(1).Item(1).TextString = "TEST"

is simply not useful.



"Bjørn Holm " wrote in message
news:6033222@discussion.autodesk.com...
Hi.

I am trying to modify the attributes of a specific block inserted into my
drawing.

I have specific reasons for not wanting to loop through the modelspace for
the correct block-element, and not using GetAttributes to receive an array
of all attributes and so on.(I am using OLE Automation from an external
application to remotly change blockattributes inside a drawing),

So my question is; Is it possible to modify attributes using the syntax
below?



ThisDrawing.Blocks(1).Item(1).TextString = "TEST"



This syntax works, I am able to write "TEST" into the specific items
TextString. But, the drawing is not updated.

Also, If I edit the drawing and change the blockattribute-values using
DDEDIT, I cannot read these changes from VBA using
ThisDrawing.Blocks(1).Item(1).TextString. It will only display blanks.


Am I missing something here? Is the blockattribute-values accessed through
DDEDIT different than the ones accessed through
ThisDrawing.Blocks(1).Item(1).TextString?



regards,
Bjørn Holm
DASH Software AS
Norway
0 Likes
Message 6 of 9

Anonymous
Not applicable
"Bjørn Holm " <=?UTF-8?Q?Bj=C3=B8rn_Holm_?=> wrote
in message news:6034035@discussion.autodesk.com...
Hi Mark.

snip

What I actually trying to do is figuring out the correct syntax for an
OLE-string that I need to send from my application(made in Clarion for
Windows(by Softvelocity)) to AutoCad.

This is the syntax for communicating through OLE in Clarion for Windows:

?AcadOLEObject{Prop:Create} = "AutoCAD.Application"
?AcadOLEObject{Prop:Ole} = "ThisDrawing.Blocks(1).Item(1).TextString =
"TEST""


snip


Sorry, never heard of Clarion,
Perhaps there's a newsgroup for that language?
You may get limited help here if you 're not using vb or vba
to my limited knowlege acad exposes an activex api and a dotnet api
if you can't hit them with Clarion then I don't know?
good luck
mark
0 Likes
Message 7 of 9

Anonymous
Not applicable
Hi again.
I am using VBA in AutoCad to perform the tasks I want. I then take the VBA
code and translate to Clarion. The translation is no problem, I don't need
help with that. What I do need is help with figure out how to do what I
want, in VBA.

And the challenge is pretty straight forward:

How do I, in VBA, in one line of code, change the value of an attribute in a
block-reference.

I find it strange if this is not possible.


regards,
Bjørn

"MP" wrote in message
news:6034064@discussion.autodesk.com...
"Bjørn Holm " <=?UTF-8?Q?Bj=C3=B8rn_Holm_?=> wrote
in message news:6034035@discussion.autodesk.com...
Hi Mark.

snip

What I actually trying to do is figuring out the correct syntax for an
OLE-string that I need to send from my application(made in Clarion for
Windows(by Softvelocity)) to AutoCad.

This is the syntax for communicating through OLE in Clarion for Windows:

?AcadOLEObject{Prop:Create} = "AutoCAD.Application"
?AcadOLEObject{Prop:Ole} = "ThisDrawing.Blocks(1).Item(1).TextString =
"TEST""


snip


Sorry, never heard of Clarion,
Perhaps there's a newsgroup for that language?
You may get limited help here if you 're not using vb or vba
to my limited knowlege acad exposes an activex api and a dotnet api
if you can't hit them with Clarion then I don't know?
good luck
mark
0 Likes
Message 8 of 9

Anonymous
Not applicable
Hi Bjrn,

There are probably worse ways than OLE but I don't know what they are.

Surely Clarion has other methods of communicating, such as writing a
lisp file (or script) to carry out the required actions, then passing a
string to AutoCAD to load the lisp file.

Could you create a macro in VBA and pass a parameter to it via an
external file or registry entry, then run the program with a string sent
to AutoCAD.

Or write the whole thing inside AutoCAD using the Clarion file as an ADO
object, getting the data from it with SQL. This is the approach I would
take.



Regards


Laurie Comerford

Bjrn Holm wrote:
> Hi again.
> I am using VBA in AutoCad to perform the tasks I want. I then take the VBA
> code and translate to Clarion. The translation is no problem, I don't need
> help with that. What I do need is help with figure out how to do what I
> want, in VBA.
>
> And the challenge is pretty straight forward:
>
> How do I, in VBA, in one line of code, change the value of an attribute in a
> block-reference.
>
> I find it strange if this is not possible.
>
>
> regards,
> Bjørn
>
> "MP" wrote in message
> news:6034064@discussion.autodesk.com...
> "Bjørn Holm " <=?UTF-8?Q?Bj=C3=B8rn_Holm_?=> wrote
> in message news:6034035@discussion.autodesk.com...
> Hi Mark.
>
> snip
>
> What I actually trying to do is figuring out the correct syntax for an
> OLE-string that I need to send from my application(made in Clarion for
> Windows(by Softvelocity)) to AutoCad.
>
> This is the syntax for communicating through OLE in Clarion for Windows:
>
> ?AcadOLEObject{Prop:Create} = "AutoCAD.Application"
> ?AcadOLEObject{Prop:Ole} = "ThisDrawing.Blocks(1).Item(1).TextString =
> "TEST""
>
>
> snip
>
>
> Sorry, never heard of Clarion,
> Perhaps there's a newsgroup for that language?
> You may get limited help here if you 're not using vb or vba
> to my limited knowlege acad exposes an activex api and a dotnet api
> if you can't hit them with Clarion then I don't know?
> good luck
> mark
0 Likes
Message 9 of 9

Anonymous
Not applicable
Hi Laurie.
I made a small macro that looks like this:

Public Function OppdaterVal(ByVal TitleBlock As String, ByVal Tag As String,
ByVal Value As String)
Dim Elem As Object
Dim Count As Integer
Dim Array1 As Variant
For Each Elem In ThisDrawing.ModelSpace
If StrComp(Elem.EntityName, "AcDbBlockReference", 1) = 0 Then
If StrComp(Elem.Name, TitleField, 1) = 0 Then
Array1 = Elem.GetAttributes
For Count = LBound(Array1) To UBound(Array1)
If Array1(Count).TagString = Tag Then
Array1(Count).TextString = Value
Exit For
End If
Next Count
Exit For
End If
End If
Next Elem
ThisDrawing.Application.Update
End Function


This macro works, it takes three parameters and lets me update whatever tag
I want in whatever block I want.

The function is stored in its own project called DASH, and the
.dvb-file(AcadOle.dvb) is loaded on startup.

But what is the correct syntax calling this function? How do I reach this
function through OLE?
I tried stuff like
?OLE{'DASH.OppdaterVal("TestBlockName","Tag1","Value1")'}, but no luck.

regards,
Bjørn Holm
DASH Software AS
Norway


"Laurie Comerford" wrote in message
news:6034110@discussion.autodesk.com...
Hi Bjrn,

There are probably worse ways than OLE but I don't know what they are.

Surely Clarion has other methods of communicating, such as writing a
lisp file (or script) to carry out the required actions, then passing a
string to AutoCAD to load the lisp file.

Could you create a macro in VBA and pass a parameter to it via an
external file or registry entry, then run the program with a string sent
to AutoCAD.

Or write the whole thing inside AutoCAD using the Clarion file as an ADO
object, getting the data from it with SQL. This is the approach I would
take.



Regards


Laurie Comerford

Bjrn Holm wrote:
> Hi again.
> I am using VBA in AutoCad to perform the tasks I want. I then take the VBA
> code and translate to Clarion. The translation is no problem, I don't need
> help with that. What I do need is help with figure out how to do what I
> want, in VBA.
>
> And the challenge is pretty straight forward:
>
> How do I, in VBA, in one line of code, change the value of an attribute in
> a
> block-reference.
>
> I find it strange if this is not possible.
>
>
> regards,
> Bjørn
>
> "MP" wrote in message
> news:6034064@discussion.autodesk.com...
> "Bjørn Holm " <=?UTF-8?Q?Bj=C3=B8rn_Holm_?=>
> wrote
> in message news:6034035@discussion.autodesk.com...
> Hi Mark.
>
> snip
>
> What I actually trying to do is figuring out the correct syntax for an
> OLE-string that I need to send from my application(made in Clarion for
> Windows(by Softvelocity)) to AutoCad.
>
> This is the syntax for communicating through OLE in Clarion for Windows:
>
> ?AcadOLEObject{Prop:Create} = "AutoCAD.Application"
> ?AcadOLEObject{Prop:Ole} = "ThisDrawing.Blocks(1).Item(1).TextString =
> "TEST""
>
>
> snip
>
>
> Sorry, never heard of Clarion,
> Perhaps there's a newsgroup for that language?
> You may get limited help here if you 're not using vb or vba
> to my limited knowlege acad exposes an activex api and a dotnet api
> if you can't hit them with Clarion then I don't know?
> good luck
> mark
0 Likes