.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Strange behaviour using GetBlockReferenceIds()

9 REPLIES 9
Reply
Message 1 of 10
jbooth
746 Views, 9 Replies

Strange behaviour using GetBlockReferenceIds()

Good afternoon,

While testing our product on a target machine I noticed something a little strange: The GetBlockReferenceIds() function returned an empty list of ObjectIds even when references did exist in the drawing.

What's strange about this is that on my machine this does not happen, and that saving and reopening the document will cause GetBlockReferenceIds() to return the correct number of block reference IDs.

The only difference between the two machines (developer machine and test machine) is that the test machine has Service Pack 2 installed.

Both machines use Autocad 2007.

Has anyone else encountered this? Should I be worried that my users will need to close/open drawings constantly, or is there a workaround?

Thanks for any help you can give.
9 REPLIES 9
Message 2 of 10
jbooth
in reply to: jbooth

In case you wanted to see some sample code, here it is.
Message 3 of 10
Anonymous
in reply to: jbooth

What release of AutoCAD was the drawing that you
tried it on last saved in?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5583994@discussion.autodesk.com...
Good afternoon,

While testing our product on a target machine I noticed something a little strange: The GetBlockReferenceIds() function returned an empty list of ObjectIds even when references did exist in the drawing.

What's strange about this is that on my machine this does not happen, and that saving and reopening the document will cause GetBlockReferenceIds() to return the correct number of block reference IDs.

The only difference between the two machines (developer machine and test machine) is that the test machine has Service Pack 2 installed.

Both machines use Autocad 2007.

Has anyone else encountered this? Should I be worried that my users will need to close/open drawings constantly, or is there a workaround?

Thanks for any help you can give.
Message 4 of 10
Anonymous
in reply to: jbooth

Jason - Take a closer look at your posted code,
specifically this line:

If blockref.OwnerId = table(AcDb.BlockTableRecord.ModelSpace) Then


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5583997@discussion.autodesk.com...
In case you wanted to see some sample code, here it is.
Message 5 of 10
Anonymous
in reply to: jbooth

Another more general comment on your code, has to do
with Disposing of objects obtained through transactions.

I see quite a bit of that in code posted here and just
wanted to point out that doing it is pointless, and only
serves to needlessly complicate your code.

In general, any objects obtained through a transaction,
do not need to be explicitly Disposed.

That's because disposing the transaction you got the
objects from, has the same effect as disposing of the
individual objects themselves.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5583997@discussion.autodesk.com...
In case you wanted to see some sample code, here it is.
Message 6 of 10
jbooth
in reply to: jbooth

To answer your questions...

The template file I am using to create any new drawings was saved in R17 format, and the drawings are either saved by the user (using qsave) or are saved using:

ThisDrawing.Database.SaveAs(FileName, AcDb.DwgVersion.Current)

As for:
If blockref.OwnerId = table(AcDb.BlockTableRecord.ModelSpace) Then

The intention was to limit objectId selection to modelspace. As far as I know, that part was working perfectly. The call to GetBlockReferenceIds() was where the code was failing.

Thanks for the heads up on the disposal of objects returned from a transaction.
Message 7 of 10
Anonymous
in reply to: jbooth

Your code uses = (assignment), but I think you
meant to use == (equality).

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5585039@discussion.autodesk.com...
To answer your questions...

The template file I am using to create any new drawings was saved in R17 format, and the drawings are either saved by the user (using qsave) or are saved using:

ThisDrawing.Database.SaveAs(FileName, AcDb.DwgVersion.Current)

As for:
If blockref.OwnerId = table(AcDb.BlockTableRecord.ModelSpace) Then

The intention was to limit objectId selection to modelspace. As far as I know, that part was working perfectly. The call to GetBlockReferenceIds() was where the code was failing.

Thanks for the heads up on the disposal of objects returned from a transaction.
Message 8 of 10
jbooth
in reply to: jbooth

in VB.NET, the = operator (when in an if statement) calls the Object.Equals() method. 🙂

I did change it to this though:
If blockref.OwnerId.Equals(table(AcDb.BlockTableRecord.ModelSpace)) Then
Message 9 of 10
Anonymous
in reply to: jbooth

Ok, sorry I must have thought I was looking at C# 🙂

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5585116@discussion.autodesk.com...
in VB.NET, the = operator (when in an if statement) calls the Object.Equals() method. 🙂

I did change it to this though:
If blockref.OwnerId.Equals(table(AcDb.BlockTableRecord.ModelSpace)) Then
Message 10 of 10
jbooth
in reply to: jbooth

To follow up on this topic:

I changed my code to use COM interop (and selection set filters) and the problem went away. I've attached a sample (although it's pretty easy).

I'll modify this again once I finish looking up the DXF code for modelspace entities, as I know I'm doing a little extra work.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost