Title Block Editor

Title Block Editor

Anonymous
Not applicable
1,096 Views
19 Replies
Message 1 of 20

Title Block Editor

Anonymous
Not applicable
I'm just starting out on a VB.NET project to build a title block
editor/drawing manager.

I ahve the start of some code I am playing with to try to understand how to
edit specific attribute values within a named block. The routine
Change_Attributes should do the trick but I'm confused about how to pass in
the ACAD block reference. I know the block I want to edit the attributes of
is.... oACAD.ActiveDocument.Blocks.Item("TITLEBLOCK_MAIN")

Block: TITLEBLOCK_MAIN
Tag: JOB1
Value: some value

Private Sub btnEditValue_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEditValue.Click

Change_Attributes(, "JOB1", "I changed this value")
End Sub

Private Sub Change_Attributes(ByVal oBlk As AcadBlockReference, ByVal
sTag As String, ByVal sValue As String)
Dim Attribs As Object
Dim Attrib As AcadAttributeReference

Attribs = oBlk.GetAttributes

For I As Integer = LBound(Attribs) To UBound(Attribs)
Attrib = Attribs(I)
If Attrib.TagString = sTag Then
Attrib.TextString = sValue
End If
Next I
End Sub


Can someone please help out?

TIA
Russ
0 Likes
1,097 Views
19 Replies
Replies (19)
Message 2 of 20

Anonymous
Not applicable
Russ,

Make a procedure to get a filtered selection set of the BlockReference(s)
you are interested in (they are called "Insert" for the filter), then pass
the object(s) into your Change_Attributes procedure. There are plenty of
examples of filtered selection sets in this ng, or the help files, or even
on our website.

--
R. Robert Bell, MCSE
www.AcadX.com


"Russ Green" wrote in message
news:51A86D9CACBF24208E33B33EC9C6529F@in.WebX.maYIadrTaRb...
| I'm just starting out on a VB.NET project to build a title block
| editor/drawing manager.
|
| I ahve the start of some code I am playing with to try to understand how
to
| edit specific attribute values within a named block. The routine
| Change_Attributes should do the trick but I'm confused about how to pass
in
| the ACAD block reference. I know the block I want to edit the attributes
of
| is.... oACAD.ActiveDocument.Blocks.Item("TITLEBLOCK_MAIN")
|
| Block: TITLEBLOCK_MAIN
| Tag: JOB1
| Value: some value
|
| Private Sub btnEditValue_Click(ByVal sender As System.Object, ByVal e
As
| System.EventArgs) Handles btnEditValue.Click
|
| Change_Attributes(, "JOB1", "I changed this value")
| End Sub
|
| Private Sub Change_Attributes(ByVal oBlk As AcadBlockReference, ByVal
| sTag As String, ByVal sValue As String)
| Dim Attribs As Object
| Dim Attrib As AcadAttributeReference
|
| Attribs = oBlk.GetAttributes
|
| For I As Integer = LBound(Attribs) To UBound(Attribs)
| Attrib = Attribs(I)
| If Attrib.TagString = sTag Then
| Attrib.TextString = sValue
| End If
| Next I
| End Sub
|
|
| Can someone please help out?
|
| TIA
| Russ
|
|
0 Likes
Message 3 of 20

Anonymous
Not applicable
Thanks for the reply. Looks like lots of useful code on your site..

So this is the code so far. But the following exception occurs..

Line of code:
ss.Select(AutoCAD.AcSelect.acSelectionSetAll, , , fType, fData)

Exception:
An unhandled exception of type 'System.NullReferenceException' occurred in
_testing application.exe

Additional information: Object reference not set to an instance of an
object.


Code:

Private Sub btnEditValue_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEditValue.Click
Dim CreateSelectionSet As Object
Dim ss As AcadSelectionSet
Dim fType As Object
Dim fData As Object

ss = CreateSelectionSet

BuildFilter(fType, fData, 0, "INSERT", 2, "TITLEBLOCK_MAIN")
ss.Select(AutoCAD.AcSelect.acSelectionSetAll, , , fType, fData)

If ss.Count > 0 Then
Change_Attributes(ss, "JOB1", "we changed this value")
End If
End Sub

Private Sub Change_Attributes(ByVal oBlk As AcadBlockReference, ByVal
sTag As String, ByVal sValue As String)
Dim Attribs As Object
Dim Attrib As AcadAttributeReference

Attribs = oBlk.GetAttributes

For I As Integer = LBound(Attribs) To UBound(Attribs)
Attrib = Attribs(I)
If Attrib.TagString = sTag Then
Attrib.TextString = sValue
End If
Next I
End Sub

Public Sub BuildFilter(ByVal typeArray, ByVal dataArray, ByVal
ParamArray gCodes())
Dim fType(), fData() As Object
Dim index As Long, i As Long

index = LBound(gCodes) - 1

For i = LBound(gCodes) To UBound(gCodes) Step 2
index = index + 1
ReDim Preserve fType(index)
ReDim Preserve fData(index)
fType(index) = CInt(gCodes(i))
fData(index) = gCodes(i + 1)
Next

typeArray = fType
dataArray = fData
End Sub




"R. Robert Bell" wrote in message
news:6EB40A017DF2688E550EA2CEF382B57F@in.WebX.maYIadrTaRb...
> Russ,
>
> Make a procedure to get a filtered selection set of the BlockReference(s)
> you are interested in (they are called "Insert" for the filter), then pass
> the object(s) into your Change_Attributes procedure. There are plenty of
> examples of filtered selection sets in this ng, or the help files, or even
> on our website.
>
> --
> R. Robert Bell, MCSE
> www.AcadX.com
>
>
> "Russ Green" wrote in message
> news:51A86D9CACBF24208E33B33EC9C6529F@in.WebX.maYIadrTaRb...
> | I'm just starting out on a VB.NET project to build a title block
> | editor/drawing manager.
> |
> | I ahve the start of some code I am playing with to try to understand how
> to
> | edit specific attribute values within a named block. The routine
> | Change_Attributes should do the trick but I'm confused about how to pass
> in
> | the ACAD block reference. I know the block I want to edit the attributes
> of
> | is.... oACAD.ActiveDocument.Blocks.Item("TITLEBLOCK_MAIN")
> |
> | Block: TITLEBLOCK_MAIN
> | Tag: JOB1
> | Value: some value
> |
> | Private Sub btnEditValue_Click(ByVal sender As System.Object, ByVal
e
> As
> | System.EventArgs) Handles btnEditValue.Click
> |
> | Change_Attributes(, "JOB1", "I changed this value")
> | End Sub
> |
> | Private Sub Change_Attributes(ByVal oBlk As AcadBlockReference,
ByVal
> | sTag As String, ByVal sValue As String)
> | Dim Attribs As Object
> | Dim Attrib As AcadAttributeReference
> |
> | Attribs = oBlk.GetAttributes
> |
> | For I As Integer = LBound(Attribs) To UBound(Attribs)
> | Attrib = Attribs(I)
> | If Attrib.TagString = sTag Then
> | Attrib.TextString = sValue
> | End If
> | Next I
> | End Sub
> |
> |
> | Can someone please help out?
> |
> | TIA
> | Russ
> |
> |
>
>
0 Likes
Message 4 of 20

Anonymous
Not applicable
Russ,
You're passing a selection set object to a function that expects a block
reference object.
or am I missing something?
> Dim ss As AcadSelectionSet
...
> Private Sub Change_Attributes(ByVal oBlk As AcadBlockReference, ByVal
...
> If ss.Count > 0 Then
> Change_Attributes(ss, "JOB1", "we changed this
value")<------is this right?
> End If

what about something like...
If ss.Count > 0 Then
dim i as long
For i = 0 to ss.count - 1
Change_Attributes(ss.item(i), "JOB1", "we changed this
value")
Next

any help?
Mark

"Russ Green" wrote in message
news:596E2F17B0D8AF1D33AD049B0AC49111@in.WebX.maYIadrTaRb...
> Thanks for the reply. Looks like lots of useful code on your site..
>
> So this is the code so far. But the following exception occurs..
>
> Line of code:
> ss.Select(AutoCAD.AcSelect.acSelectionSetAll, , , fType, fData)
>
> Exception:
> An unhandled exception of type 'System.NullReferenceException' occurred in
> _testing application.exe
>
> Additional information: Object reference not set to an instance of an
> object.
>
>
> Code:
>
> Private Sub btnEditValue_Click(ByVal sender As System.Object, ByVal e
As
> System.EventArgs) Handles btnEditValue.Click
> Dim CreateSelectionSet As Object
> Dim ss As AcadSelectionSet
> Dim fType As Object
> Dim fData As Object
>
> ss = CreateSelectionSet
>
> BuildFilter(fType, fData, 0, "INSERT", 2, "TITLEBLOCK_MAIN")
> ss.Select(AutoCAD.AcSelect.acSelectionSetAll, , , fType, fData)
>
> If ss.Count > 0 Then
> Change_Attributes(ss, "JOB1", "we changed this value")
> End If
> End Sub
>
> Private Sub Change_Attributes(ByVal oBlk As AcadBlockReference, ByVal
> sTag As String, ByVal sValue As String)
> Dim Attribs As Object
> Dim Attrib As AcadAttributeReference
>
> Attribs = oBlk.GetAttributes
>
> For I As Integer = LBound(Attribs) To UBound(Attribs)
> Attrib = Attribs(I)
> If Attrib.TagString = sTag Then
> Attrib.TextString = sValue
> End If
> Next I
> End Sub
>
> Public Sub BuildFilter(ByVal typeArray, ByVal dataArray, ByVal
> ParamArray gCodes())
> Dim fType(), fData() As Object
> Dim index As Long, i As Long
>
> index = LBound(gCodes) - 1
>
> For i = LBound(gCodes) To UBound(gCodes) Step 2
> index = index + 1
> ReDim Preserve fType(index)
> ReDim Preserve fData(index)
> fType(index) = CInt(gCodes(i))
> fData(index) = gCodes(i + 1)
> Next
>
> typeArray = fType
> dataArray = fData
> End Sub
>
>
>
>
> "R. Robert Bell" wrote in message
> news:6EB40A017DF2688E550EA2CEF382B57F@in.WebX.maYIadrTaRb...
> > Russ,
> >
> > Make a procedure to get a filtered selection set of the
BlockReference(s)
> > you are interested in (they are called "Insert" for the filter), then
pass
> > the object(s) into your Change_Attributes procedure. There are plenty of
> > examples of filtered selection sets in this ng, or the help files, or
even
> > on our website.
> >
> > --
> > R. Robert Bell, MCSE
> > www.AcadX.com
> >
> >
> > "Russ Green" wrote in message
> > news:51A86D9CACBF24208E33B33EC9C6529F@in.WebX.maYIadrTaRb...
> > | I'm just starting out on a VB.NET project to build a title block
> > | editor/drawing manager.
> > |
> > | I ahve the start of some code I am playing with to try to understand
how
> > to
> > | edit specific attribute values within a named block. The routine
> > | Change_Attributes should do the trick but I'm confused about how to
pass
> > in
> > | the ACAD block reference. I know the block I want to edit the
attributes
> > of
> > | is.... oACAD.ActiveDocument.Blocks.Item("TITLEBLOCK_MAIN")
> > |
> > | Block: TITLEBLOCK_MAIN
> > | Tag: JOB1
> > | Value: some value
> > |
> > | Private Sub btnEditValue_Click(ByVal sender As System.Object,
ByVal
> e
> > As
> > | System.EventArgs) Handles btnEditValue.Click
> > |
> > | Change_Attributes(, "JOB1", "I changed this value")
> > | End Sub
> > |
> > | Private Sub Change_Attributes(ByVal oBlk As AcadBlockReference,
> ByVal
> > | sTag As String, ByVal sValue As String)
> > | Dim Attribs As Object
> > | Dim Attrib As AcadAttributeReference
> > |
> > | Attribs = oBlk.GetAttributes
> > |
> > | For I As Integer = LBound(Attribs) To UBound(Attribs)
> > | Attrib = Attribs(I)
> > | If Attrib.TagString = sTag Then
> > | Attrib.TextString = sValue
> > | End If
> > | Next I
> > | End Sub
> > |
> > |
> > | Can someone please help out?
> > |
> > | TIA
> > | Russ
> > |
> > |
> >
> >
>
>
0 Likes
Message 5 of 20

Anonymous
Not applicable
Mark,

That does make sense but the code still falls over at this line,
ss.Select(AutoCAD.AcSelect.acSelectionSetAll, , , fType, fData)

Before it even gets to,
Change_Attributes(ss.item(i), "JOB1", "we changed this value")

This is still the same exception
An unhandled exception of type 'System.NullReferenceException' occurred in
_testing application.exe

Additional information: Object reference not set to an instance of an
object.



"Mark Propst" wrote in message
news:8B481613075A85CCD0FB320C00DE95BE@in.WebX.maYIadrTaRb...
> Russ,
> You're passing a selection set object to a function that expects a block
> reference object.
> or am I missing something?
> > Dim ss As AcadSelectionSet
> ...
> > Private Sub Change_Attributes(ByVal oBlk As AcadBlockReference,
ByVal
> ...
> > If ss.Count > 0 Then
> > Change_Attributes(ss, "JOB1", "we changed this
> value")<------is this right?
> > End If
>
> what about something like...
> If ss.Count > 0 Then
> dim i as long
> For i = 0 to ss.count - 1
> Change_Attributes(ss.item(i), "JOB1", "we changed this
> value")
> Next
>
> any help?
> Mark
>
> "Russ Green" wrote in message
> news:596E2F17B0D8AF1D33AD049B0AC49111@in.WebX.maYIadrTaRb...
> > Thanks for the reply. Looks like lots of useful code on your site..
> >
> > So this is the code so far. But the following exception occurs..
> >
> > Line of code:
> > ss.Select(AutoCAD.AcSelect.acSelectionSetAll, , , fType, fData)
> >
> > Exception:
> > An unhandled exception of type 'System.NullReferenceException' occurred
in
> > _testing application.exe
> >
> > Additional information: Object reference not set to an instance of an
> > object.
> >
> >
> > Code:
> >
> > Private Sub btnEditValue_Click(ByVal sender As System.Object, ByVal
e
> As
> > System.EventArgs) Handles btnEditValue.Click
> > Dim CreateSelectionSet As Object
> > Dim ss As AcadSelectionSet
> > Dim fType As Object
> > Dim fData As Object
> >
> > ss = CreateSelectionSet
> >
> > BuildFilter(fType, fData, 0, "INSERT", 2, "TITLEBLOCK_MAIN")
> > ss.Select(AutoCAD.AcSelect.acSelectionSetAll, , , fType, fData)
> >
> > If ss.Count > 0 Then
> > Change_Attributes(ss, "JOB1", "we changed this value")
> > End If
> > End Sub
> >
> > Private Sub Change_Attributes(ByVal oBlk As AcadBlockReference,
ByVal
> > sTag As String, ByVal sValue As String)
> > Dim Attribs As Object
> > Dim Attrib As AcadAttributeReference
> >
> > Attribs = oBlk.GetAttributes
> >
> > For I As Integer = LBound(Attribs) To UBound(Attribs)
> > Attrib = Attribs(I)
> > If Attrib.TagString = sTag Then
> > Attrib.TextString = sValue
> > End If
> > Next I
> > End Sub
> >
> > Public Sub BuildFilter(ByVal typeArray, ByVal dataArray, ByVal
> > ParamArray gCodes())
> > Dim fType(), fData() As Object
> > Dim index As Long, i As Long
> >
> > index = LBound(gCodes) - 1
> >
> > For i = LBound(gCodes) To UBound(gCodes) Step 2
> > index = index + 1
> > ReDim Preserve fType(index)
> > ReDim Preserve fData(index)
> > fType(index) = CInt(gCodes(i))
> > fData(index) = gCodes(i + 1)
> > Next
> >
> > typeArray = fType
> > dataArray = fData
> > End Sub
> >
> >
> >
> >
> > "R. Robert Bell" wrote in message
> > news:6EB40A017DF2688E550EA2CEF382B57F@in.WebX.maYIadrTaRb...
> > > Russ,
> > >
> > > Make a procedure to get a filtered selection set of the
> BlockReference(s)
> > > you are interested in (they are called "Insert" for the filter), then
> pass
> > > the object(s) into your Change_Attributes procedure. There are plenty
of
> > > examples of filtered selection sets in this ng, or the help files, or
> even
> > > on our website.
> > >
> > > --
> > > R. Robert Bell, MCSE
> > > www.AcadX.com
> > >
> > >
> > > "Russ Green" wrote in message
> > > news:51A86D9CACBF24208E33B33EC9C6529F@in.WebX.maYIadrTaRb...
> > > | I'm just starting out on a VB.NET project to build a title block
> > > | editor/drawing manager.
> > > |
> > > | I ahve the start of some code I am playing with to try to understand
> how
> > > to
> > > | edit specific attribute values within a named block. The routine
> > > | Change_Attributes should do the trick but I'm confused about how to
> pass
> > > in
> > > | the ACAD block reference. I know the block I want to edit the
> attributes
> > > of
> > > | is.... oACAD.ActiveDocument.Blocks.Item("TITLEBLOCK_MAIN")
> > > |
> > > | Block: TITLEBLOCK_MAIN
> > > | Tag: JOB1
> > > | Value: some value
> > > |
> > > | Private Sub btnEditValue_Click(ByVal sender As System.Object,
> ByVal
> > e
> > > As
> > > | System.EventArgs) Handles btnEditValue.Click
> > > |
> > > | Change_Attributes(, "JOB1", "I changed this value")
> > > | End Sub
> > > |
> > > | Private Sub Change_Attributes(ByVal oBlk As AcadBlockReference,
> > ByVal
> > > | sTag As String, ByVal sValue As String)
> > > | Dim Attribs As Object
> > > | Dim Attrib As AcadAttributeReference
> > > |
> > > | Attribs = oBlk.GetAttributes
> > > |
> > > | For I As Integer = LBound(Attribs) To UBound(Attribs)
> > > | Attrib = Attribs(I)
> > > | If Attrib.TagString = sTag Then
> > > | Attrib.TextString = sValue
> > > | End If
> > > | Next I
> > > | End Sub
> > > |
> > > |
> > > | Can someone please help out?
> > > |
> > > | TIA
> > > | Russ
> > > |
> > > |
> > >
> > >
> >
> >
>
>
0 Likes
Message 6 of 20

Anonymous
Not applicable
ss can't be set to an object of any type other than AcadSelectionSet.
Where are you giving CreateSelectionSet a value?

___________________________
Mike Tuersley
AutoCAD Clinic
Rand IMAGINiT Technologies
0 Likes
Message 7 of 20

Anonymous
Not applicable
well I don't know .net .yet so,
this line looks weird to me
ss.Select(AutoCAD.AcSelect.acSelectionSetAll, , , fType, fData)
(I don't understand the AutoCAD.AcSelect. part of it,)
in vb it would just be
ss.Select acSelectionSetAll, , , fType, fData
so if in .net you're having to identify the constant acSelect with the
preface AutoCAD.AcSelect. for some reason, then why are the args in parens?
if it were vb, since the Select method is not a function returning a value
it would be like:
ss.Select AutoCAD.AcSelect.acSelectionSetAll, , , fType, fData

if it were a function returning a value it would be something like:
(if return was an object)
set something = ss.Select(AutoCAD.AcSelect.acSelectionSetAll, , , fType,
fData)
or
(if return wasn't an object)
something = ss.Select(AutoCAD.AcSelect.acSelectionSetAll, , , fType, fData)

if that's not the problem then i'd look at each object to see which one
isn't set
'System.NullReferenceException' sounds like something that's supposed to be
an object isn't.
so at the point it fails set a watch to ss and AutoCad and see if one of
them is = Nothing for some reason,
the problem would probably, in that event, be somewhere above this line of
code that was supposed to initialize either ss or AutoCad
also in your orig post you were using oAcad , are you changing your variable
names each time?

"I know the block I want to edit the attributes of
is.... oACAD.ActiveDocument.Blocks.Item("TITLEBLOCK_MAIN")"


makes it a little hard to follow exactly whats going on...

you can also put a line before your selection line like:
If ss IsNothing then
Debug.print "warning ss is having a bad day"
elseIf AutoCad(or oAcad or whatever its' really supposed to be) IsNothing
then
Debug.print "warning acad is having a really bad day"
else
....continue with selection attempt
end if
just to help in tracking down the problem

good luck and happy bug hunting! 🙂
Mark

"Russ Green" wrote in message
news:4684D00B17682A9A5FFB5D92E64EAB97@in.WebX.maYIadrTaRb...
> Mark,
>
> That does make sense but the code still falls over at this line,
> ss.Select(AutoCAD.AcSelect.acSelectionSetAll, , , fType, fData)
0 Likes
Message 8 of 20

Anonymous
Not applicable
> ss can't be set to an object of any type other than AcadSelectionSet.
but it is?

> Where are you giving CreateSelectionSet a value?
my mistake.

A slight tweak then but still errors in the same place...

Private Sub btnEditValue_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEditValue.Click
Dim ss As AcadSelectionSet
Dim fType(1) As Object
Dim fData(1) As Object
Dim oBlock As AcadBlock

'make the empty selection set
ss = CreateSelectionSet()

'build the selection filter
fType(0) = 0 : fData(0) = "INSERT"
fType(1) = 2 : fData(1) = "TITLEBLOCK_MAIN"

'make the selection
'ss.Highlight(True)
ss.Select(AutoCAD.AcSelect.acSelectionSetAll, , , fType, fData)

If ss.Count > 0 Then
Dim i As Long
For i = 0 To ss.Count - 1
Change_Attributes(ss.Item(i), "JOB1", "we changed this
value")
Next
End If
End Sub


"Mike Tuersley" wrote in message
news:MPG.1a3d0868efc7e8ac9897c6@discussion.autodesk.com...
> ss can't be set to an object of any type other than AcadSelectionSet.
> Where are you giving CreateSelectionSet a value?
>
> ___________________________
> Mike Tuersley
> AutoCAD Clinic
> Rand IMAGINiT Technologies
0 Likes
Message 9 of 20

Anonymous
Not applicable
you're sure it's not...
ss.Select AutoCAD.AcSelect.acSelectionSetAll, , , fType, fData
?


"Russ Green" wrote in message
news:D0807A203AB8E59BF5A8405104AA653A@in.WebX.maYIadrTaRb...
> > ss can't be set to an object of any type other than AcadSelectionSet.
> but it is?
>
0 Likes
Message 10 of 20

Anonymous
Not applicable
Well .NET completes the parenthesis automatically. It's impossible not to
have them it's the syntax.

Thanks for your responses anyway.

So if you were trying to select a block and edit specific attributes (by tag
name) in vb6 how would you do it differently?

Russ

"Mark Propst" wrote in message
news:327FE25ED988EEA7EA944755CCFCE27B@in.WebX.maYIadrTaRb...
> well I don't know .net .yet so,
> this line looks weird to me
> ss.Select(AutoCAD.AcSelect.acSelectionSetAll, , , fType, fData)
> (I don't understand the AutoCAD.AcSelect. part of it,)
> in vb it would just be
> ss.Select acSelectionSetAll, , , fType, fData
> so if in .net you're having to identify the constant acSelect with the
> preface AutoCAD.AcSelect. for some reason, then why are the args in
parens?
> if it were vb, since the Select method is not a function returning a value
> it would be like:
> ss.Select AutoCAD.AcSelect.acSelectionSetAll, , , fType, fData
>
> if it were a function returning a value it would be something like:
> (if return was an object)
> set something = ss.Select(AutoCAD.AcSelect.acSelectionSetAll, , , fType,
> fData)
> or
> (if return wasn't an object)
> something = ss.Select(AutoCAD.AcSelect.acSelectionSetAll, , , fType,
fData)
>
> if that's not the problem then i'd look at each object to see which one
> isn't set
> 'System.NullReferenceException' sounds like something that's supposed to
be
> an object isn't.
> so at the point it fails set a watch to ss and AutoCad and see if one of
> them is = Nothing for some reason,
> the problem would probably, in that event, be somewhere above this line of
> code that was supposed to initialize either ss or AutoCad
> also in your orig post you were using oAcad , are you changing your
variable
> names each time?
>
> "I know the block I want to edit the attributes of
> is.... oACAD.ActiveDocument.Blocks.Item("TITLEBLOCK_MAIN")"
>
>
> makes it a little hard to follow exactly whats going on...
>
> you can also put a line before your selection line like:
> If ss IsNothing then
> Debug.print "warning ss is having a bad day"
> elseIf AutoCad(or oAcad or whatever its' really supposed to be) IsNothing
> then
> Debug.print "warning acad is having a really bad day"
> else
> ....continue with selection attempt
> end if
> just to help in tracking down the problem
>
> good luck and happy bug hunting! 🙂
> Mark
>
> "Russ Green" wrote in message
> news:4684D00B17682A9A5FFB5D92E64EAB97@in.WebX.maYIadrTaRb...
> > Mark,
> >
> > That does make sense but the code still falls over at this line,
> > ss.Select(AutoCAD.AcSelect.acSelectionSetAll, , , fType, fData)
>
>
>
0 Likes
Message 11 of 20

Anonymous
Not applicable
sorry, like i said i know nothing about .net
as I mentioned before, in vb the selection would look like:
ss.Select acSelectionSetAll, , , fType, fData

but obviously that's not the case in .net so hopefully some one whos not
.net challenged will step in


"Russ Green" wrote in message
news:13F33A3DA6D85B3818F1E99E0838ACEB@in.WebX.maYIadrTaRb...
> Well .NET completes the parenthesis automatically. It's impossible not to
> have them it's the syntax.
>
> Thanks for your responses anyway.
>
> So if you were trying to select a block and edit specific attributes (by
tag
> name) in vb6 how would you do it differently?
>
> Russ
0 Likes
Message 12 of 20

Anonymous
Not applicable
Yes, show us what CreateSelectionSet is defined as. That is more than
likely where your error is based on the rest of the code you have alredy
shown - it is not part of the AutoCAD API.
___________________________
Mike Tuersley
AutoCAD Clinic
Rand IMAGINiT Technologies
0 Likes
Message 13 of 20

Anonymous
Not applicable
It's the same in .net as well because this is relating specifically to
the AutoCAD API and not .NET. The issue is the CreateSelectionSet - it
has to return an AcadSelectionSet object. Until we see what/how it is
defined, the thread is pointless - we are speaking one thing and Russ
another. Regardless of the language, by declaring an object of a certain
type, it can only be set to that same type.
___________________________
Mike Tuersley
AutoCAD Clinic
Rand IMAGINiT Technologies
0 Likes
Message 14 of 20

Anonymous
Not applicable
Russ Green wrote:

> Line of code:
> ss.Select(AutoCAD.AcSelect.acSelectionSetAll, , , fType, fData)
>
> Exception:
> An unhandled exception of type 'System.NullReferenceException'
> occurred in _testing application.exe
>
> Additional information: Object reference not set to an instance of an
> object.

Judging from the routine names, you're using toolbox functions from our
site or a knock-off of them. Considering that we have not posted .NET
versions of BuildFilter or CreateSelectionSet (just how *did* you manage
to call it without parens?), I'd say your problem is somewhere in one of
those two routines. Please post them for review.

Some other things to consider:

1) The arguments you're passing for the selection set filter should be
of type Short() and Object(), respectively.

2) BuildFilter is really overkill for filters in .NET. Check this out:

Dim fType As Short() = {0, 2}
Dim fData As Object() = {"INSERT", "TITLEBLOCK_MAIN"}

3) Your selection set object is declared as Object instead of
AcadSelectionSet. While legal (everything derives from Object), it's not
only pointless but a hindrance as you'd have to call all members via
late binding. This is definitely not the way to go.

P.S. I just noticed that you already posted BuildFilter. All I can say
is "Yikes!". While that code is useful in VBA, it's hardly tuned for
.NET. You have to remember that all our VBA stuff is meant for a
language far more crude than VB.NET.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
0 Likes
Message 15 of 20

Anonymous
Not applicable
That was a mistake as I declared in by accident.

The CreateSelectionSet funtion looks like this
Public Function CreateSelectionSet(Optional ByVal ssName As String =
"ss") As AcadSelectionSet
Dim ss As AcadSelectionSet
Try
ss = oACAD.ActiveDocument.SelectionSets.Item(ssName)
Catch ex As Exception
ss = oACAD.ActiveDocument.SelectionSets.Add(ssName)
ss.Clear()
End Try
End Function

And the main routine looks like this....

as you can see I have already removed BuildFilter() so only leaves
CreateSelectionSet() as a possible problem.

Private Sub btnEditValue_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEditValue.Click
Dim ss As AcadSelectionSet
Dim fType(1) As Short
Dim fData(1) As Object
Dim Pt1(0) As Double
Dim Pt2(0) As Double
Dim oBlock As AcadBlock

'make the empty selection set
ss = CreateSelectionSet()

'build the selection filter
fType(0) = 0 : fData(0) = "INSERT"
fType(1) = 2 : fData(1) = "TITLEBLOCK_MAIN"

'make the selection
'ss.Highlight(True)
ss.Select(AcSelect.acSelectionSetAll, Pt1, Pt2, fType, fData)

If ss.Count >= 1 Then
Dim i As Long
For i = 0 To ss.Count
Change_Attributes(DirectCast(ss.Item(i),
AcadBlockReference), "JOB1", "we changed this value")
Next
End If
End Sub

And it still falls over here
ss.Select(AcSelect.acSelectionSetAll, Pt1, Pt2, fType, fData)

Russ

"Frank Oquendo" wrote in message
news:D3A3630D7620236721194FB8CD560254@in.WebX.maYIadrTaRb...
> Russ Green wrote:
>
> > Line of code:
> > ss.Select(AutoCAD.AcSelect.acSelectionSetAll, , , fType, fData)
> >
> > Exception:
> > An unhandled exception of type 'System.NullReferenceException'
> > occurred in _testing application.exe
> >
> > Additional information: Object reference not set to an instance of an
> > object.
>
> Judging from the routine names, you're using toolbox functions from our
> site or a knock-off of them. Considering that we have not posted .NET
> versions of BuildFilter or CreateSelectionSet (just how *did* you manage
> to call it without parens?), I'd say your problem is somewhere in one of
> those two routines. Please post them for review.
>
> Some other things to consider:
>
> 1) The arguments you're passing for the selection set filter should be
> of type Short() and Object(), respectively.
>
> 2) BuildFilter is really overkill for filters in .NET. Check this out:
>
> Dim fType As Short() = {0, 2}
> Dim fData As Object() = {"INSERT", "TITLEBLOCK_MAIN"}
>
> 3) Your selection set object is declared as Object instead of
> AcadSelectionSet. While legal (everything derives from Object), it's not
> only pointless but a hindrance as you'd have to call all members via
> late binding. This is definitely not the way to go.
>
> P.S. I just noticed that you already posted BuildFilter. All I can say
> is "Yikes!". While that code is useful in VBA, it's hardly tuned for
> .NET. You have to remember that all our VBA stuff is meant for a
> language far more crude than VB.NET.
>
> --
> There are 10 kinds of people. Those who understand binary and those who
> don't.
>
> http://code.acadx.com
> (Pull the pin to reply)
>
>
0 Likes
Message 16 of 20

Anonymous
Not applicable
>by declaring an object of a certain type, it can only be set to that same
type.

Yeah but the language has to let you declare the correct type in the first
place. It's not .NET its language syntax/structure of VB.NET

Russ


"Mike Tuersley" wrote in message
news:MPG.1a3db8629133fa5f9897c8@discussion.autodesk.com...
> It's the same in .net as well because this is relating specifically to
> the AutoCAD API and not .NET. The issue is the CreateSelectionSet - it
> has to return an AcadSelectionSet object. Until we see what/how it is
> defined, the thread is pointless - we are speaking one thing and Russ
> another. Regardless of the language, by declaring an object of a certain
> type, it can only be set to that same type.
> ___________________________
> Mike Tuersley
> AutoCAD Clinic
> Rand IMAGINiT Technologies
0 Likes
Message 17 of 20

Anonymous
Not applicable
Russ Green wrote:

> The CreateSelectionSet funtion looks like this
> Public Function CreateSelectionSet(Optional ByVal ssName As
> String = "ss") As AcadSelectionSet
> Dim ss As AcadSelectionSet
> Try
> ss = oACAD.ActiveDocument.SelectionSets.Item(ssName)
> Catch ex As Exception
> ss = oACAD.ActiveDocument.SelectionSets.Add(ssName)
> ss.Clear()
> End Try
> End Function

First, you're not actually returning the selection set; there's no
return statement. Second, move the ss.Clear into the Finally block so it
gets cleared either way.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
0 Likes
Message 18 of 20

Anonymous
Not applicable
So it should be this? You know when you stare at a problem for so long you
overlook the simple errors screeming at you.

Public Function CreateSelectionSet(Optional ByVal ssName As String = "ss")
As AcadSelectionSet
Dim ss As AcadSelectionSet
Try
ss = oACAD.ActiveDocument.SelectionSets.Item(ssName)
Catch ex As Exception
ss = oACAD.ActiveDocument.SelectionSets.Add(ssName)
End Try
ss.Clear()
Return ss
End Function

"Frank Oquendo" wrote in message
news:C7BC3C20BEB4F00D2569D05FFBE2B2E2@in.WebX.maYIadrTaRb...
> Russ Green wrote:
>
> > The CreateSelectionSet funtion looks like this
> > Public Function CreateSelectionSet(Optional ByVal ssName As
> > String = "ss") As AcadSelectionSet
> > Dim ss As AcadSelectionSet
> > Try
> > ss = oACAD.ActiveDocument.SelectionSets.Item(ssName)
> > Catch ex As Exception
> > ss = oACAD.ActiveDocument.SelectionSets.Add(ssName)
> > ss.Clear()
> > End Try
> > End Function
>
> First, you're not actually returning the selection set; there's no
> return statement. Second, move the ss.Clear into the Finally block so it
> gets cleared either way.
>
> --
> There are 10 kinds of people. Those who understand binary and those who
> don't.
>
> http://code.acadx.com
> (Pull the pin to reply)
>
>
0 Likes
Message 19 of 20

Anonymous
Not applicable
Russ Green wrote:
> So it should be this?

Real close. See below. I added a Finalyl clause and moved ss.Clear into
it.

> You know when you stare at a problem for so
> long you overlook the simple errors screeming at you.

I know *exactly* what you mean. 😉

> Public Function CreateSelectionSet(Optional ByVal ssName As String =
> "ss") As AcadSelectionSet
> Dim ss As AcadSelectionSet
> Try
> ss = oACAD.ActiveDocument.SelectionSets.Item(ssName)
> Catch ex As Exception
> ss = oACAD.ActiveDocument.SelectionSets.Add(ssName)
> Finally
> ss.Clear()
> End Try
> Return ss
> End Function

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
0 Likes
Message 20 of 20

Anonymous
Not applicable
OK, Thanks for all your responses. I have the basic functions working now.
So I can now change the value of a named attribute within a named block in
the active drawing.

Next to begin working on the revision block strategy.........

I'll post the basic code for the attribute editor if anyone requests it.

Russ

"Russ Green" wrote in message
news:51A86D9CACBF24208E33B33EC9C6529F@in.WebX.maYIadrTaRb...
> I'm just starting out on a VB.NET project to build a title block
> editor/drawing manager.
>
> I ahve the start of some code I am playing with to try to understand how
to
> edit specific attribute values within a named block. The routine
> Change_Attributes should do the trick but I'm confused about how to pass
in
> the ACAD block reference. I know the block I want to edit the attributes
of
> is.... oACAD.ActiveDocument.Blocks.Item("TITLEBLOCK_MAIN")
>
> Block: TITLEBLOCK_MAIN
> Tag: JOB1
> Value: some value
>
> Private Sub btnEditValue_Click(ByVal sender As System.Object, ByVal e
As
> System.EventArgs) Handles btnEditValue.Click
>
> Change_Attributes(, "JOB1", "I changed this value")
> End Sub
>
> Private Sub Change_Attributes(ByVal oBlk As AcadBlockReference, ByVal
> sTag As String, ByVal sValue As String)
> Dim Attribs As Object
> Dim Attrib As AcadAttributeReference
>
> Attribs = oBlk.GetAttributes
>
> For I As Integer = LBound(Attribs) To UBound(Attribs)
> Attrib = Attribs(I)
> If Attrib.TagString = sTag Then
> Attrib.TextString = sValue
> End If
> Next I
> End Sub
>
>
> Can someone please help out?
>
> TIA
> Russ
>
>
0 Likes