.NET

Reply
Mentor
SENL1362
Posts: 213
Registered: ‎07-20-2011
Message 1 of 8 (159 Views)
Accepted Solution

Zoom to Block Reference

159 Views, 7 Replies
07-09-2014 02:20 AM

Hello Forum,

Can someone tell me why a just created BlockReference does not have GeometricExtents.

                    BlockReference dxfBlkRef = new BlockReference(Point3d.Origin, dxfBlkId);
                    ms.UpgradeOpen();
                    ms.AppendEntity(dxfBlkRef);
                    tr.AddNewlyCreatedDBObject(dxfBlkRef, true);
                    try
                    {
                        //This failed because the BlockReference does not have Extents yet
                        ZoomUtils.ZoomObjects(doc, new ObjectId[] { dxfBlkRef.ObjectId });
                    }
                    catch
                    {
                        //Summing the Extents of the Nested objects solve this problem
                        Extents3d blkRefExts = GetBlockRefExtentsByNestedEntities(dxfBlkRef);
                        ZoomUtils.ZoomExtents(doc, blkRefExts);
                    }

 

A solution is to explode the BlockReference but i like to avoid that.

Other solutions tried are:

- different versions of AutoCAD (2012+2014)

- dxfBlkRef.GeometryExtentsBestFit()

 

Attached is the code and a DXF sample

 

Thanks for any advise.

 

 

hello.

you have to validate the transaction .

After that you can have the geometry extend.

 

The block is inserted after the validate of the transaction.

 

 

 

You can start a new transaction and retrieve again the BlockReference using the original ObjectId. The ObjectId is guaranteed to remain constant inside an database Open-Close cycle.

Valued Mentor
AubelecBE
Posts: 398
Registered: ‎01-27-2010
Message 2 of 8 (149 Views)

Re: Zoom to Block Reference

07-09-2014 03:16 AM in reply to: SENL1362

hello.

you have to validate the transaction .

After that you can have the geometry extend.

 

The block is inserted after the validate of the transaction.

 

 

 

Mentor
SENL1362
Posts: 213
Registered: ‎07-20-2011
Message 3 of 8 (143 Views)

Re: Zoom to Block Reference

07-09-2014 03:25 AM in reply to: AubelecBE
You mean i have to Commit the transaction first?
Then how to organise Transactions because after Zoom to the BlockReference i want to ExplodeToOwnerSpace?
Therefore i need to copy the Object to another Transaction
Distinguished Contributor
mcicognani
Posts: 131
Registered: ‎12-01-2004
Message 4 of 8 (133 Views)

Re: Zoom to Block Reference

07-09-2014 05:15 AM in reply to: SENL1362

You can start a new transaction and retrieve again the BlockReference using the original ObjectId. The ObjectId is guaranteed to remain constant inside an database Open-Close cycle.

Mentor
SENL1362
Posts: 213
Registered: ‎07-20-2011
Message 5 of 8 (128 Views)

Re: Zoom to Block Reference

07-09-2014 05:33 AM in reply to: AubelecBE
many thanks
Mentor
SENL1362
Posts: 213
Registered: ‎07-20-2011
Message 6 of 8 (128 Views)

Re: Zoom to Block Reference

07-09-2014 05:34 AM in reply to: mcicognani
again many thanks
Valued Mentor
AubelecBE
Posts: 398
Registered: ‎01-27-2010
Message 7 of 8 (101 Views)

Re: Zoom to Block Reference

07-09-2014 11:21 PM in reply to: SENL1362

usualy I do :

- open new transaction

- Insert Block

- retreave the Object Id (If i dont close the file)

- retreave the handle (If i close the file but i want to save the Id of the block)

- commit the transaction.

 

- regen

 

- open new transaction

- retrieve the block ref with ObecjtId or Handle.

- modify etc..

- commit the transaction.

 

The ObjectId is the same in the same file. but if you close, re open the file the objectId is not the same. For this use the Handle (a string)

Mentor
SENL1362
Posts: 213
Registered: ‎07-20-2011
Message 8 of 8 (95 Views)

Re: Zoom to Block Reference

07-09-2014 11:30 PM in reply to: AubelecBE
Thank you for showing the steps to solve this issue.
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!