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

Zoom to Block Reference

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
SENL1362
1039 Views, 7 Replies

Zoom to Block Reference

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.

 

 

7 REPLIES 7
Message 2 of 8
AubelecBE
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.

 

 

 

Message 3 of 8
SENL1362
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
Message 4 of 8
mcicognani
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.

Message 5 of 8
SENL1362
in reply to: AubelecBE

many thanks
Message 6 of 8
SENL1362
in reply to: mcicognani

again many thanks
Message 7 of 8
AubelecBE
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)

Message 8 of 8
SENL1362
in reply to: AubelecBE

Thank you for showing the steps to solve this issue.

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