.NET

.NET

Reply
Valued Mentor
AubelecBE
Posts: 387
Registered: ‎01-27-2010
Message 1 of 7 (283 Views)

How to create a good rectangle for a block with GeometricExtents

283 Views, 6 Replies
02-03-2013 09:04 AM

HI,

i have created a block with n attribute.

i insert the block with attribute filled with fields.

I send the commande "Regen" for update field.

 

Now i want to add a rectangle in the block définition.

I use GeometricExtents. 

 

it works fine only when then the rotation is 0 and UCS on UCSW.

 

how i can create the line with the 4 points ? I want the line include all entity in my block def.

 

 

I joined a zip with :

2.dwg is the XRef in 3.dwg

My bloc show info from xref (2.dwg).

 

in the dwg. the bloc contain a line. The libe i manualy added when i create the blockreccord

ADN Support Specialist
philippe.leefsma
Posts: 625
Registered: ‎06-02-2009
Message 2 of 7 (243 Views)

Re: How to create a good rectangle for a block with GeometricExtents

02-10-2013 10:04 AM in reply to: AubelecBE

Hi There,

 

You mention you want to add the rectangle in the block definition, but GeometricExtents is only returned on Entities, so if your block doesn't contain too many entities, you can open the block definition, iterate through all ObjectIds, open each entity and check its extents.

 

Another approach would be to retrieve the extents of the block reference, apply the inverse transformation of the block reference to that extents, so you would have it express in block definition space.

 

Regards,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Valued Mentor
AubelecBE
Posts: 387
Registered: ‎01-27-2010
Message 3 of 7 (214 Views)

Re: How to create a good rectangle for a block with GeometricExtents

02-15-2013 04:15 AM in reply to: philippe.leefsma

i have to use your second solution.

I use attribut with field.

The field is fiiled when i insert the block in my dwg.

So i need to insert my bloc and use GeometricExtend for retrieve the extend point.

 

But it work when i have a the World UCS or User UCS (but only with then UCS in a plane of the editor.).

 

I Dont know how to calculate the correct POint for create my line when i retrieve point in UCS with a different angle other than 0 or 180 ( angle from UCS and the view in editor.)

 

 

 

 

here a saple of my code :

 

 'Création du Rectangle
        Dim ext As Extents3d
        ext = RefBloc.GeometricExtents
        ext.TransformBy(Ed.CurrentUserCoordinateSystem.Inverse())
        ''test  affichage du carré :
        Dim Newrec As New Autodesk.AutoCAD.DatabaseServices.Polyline
        Newrec.AddVertexAt(0, New Point2d(-5, 5), 0, 0, 0)
        Newrec.AddVertexAt(1, New Point2d((System.Math.Abs(ext.MaxPoint.X - ext.MinPoint.X) / RefBloc.ScaleFactors.X) + 5, 5), 0, 0, 0)
        Newrec.AddVertexAt(2, New Point2d((System.Math.Abs(ext.MaxPoint.X - ext.MinPoint.X) / RefBloc.ScaleFactors.X) + 5, (-(System.Math.Abs(ext.MaxPoint.Y - ext.MinPoint.Y)) / RefBloc.ScaleFactors.Y) - 5), 0, 0, 0)
        Newrec.AddVertexAt(3, New Point2d(-5, (-System.Math.Abs(ext.MaxPoint.Y - ext.MinPoint.Y) / RefBloc.ScaleFactors.Y) - 5), 0, 0, 0)
        Newrec.Closed = True
        Newrec.Layer = "0"
        tr = db.TransactionManager.StartTransaction
        Dim btr As BlockTableRecord = tr.GetObject(DefBloc.ObjectId, OpenMode.ForWrite)
        btr.AppendEntity(Newrec)
        tr.AddNewlyCreatedDBObject(Newrec, True)
        tr.Commit()

 

Ths prob : GeometricExtents return 2 points in UCW  i need to translate for create a line  in my BlockDefinition.

 

 

Moderator
Alexander.Rivilis
Posts: 1,406
Registered: ‎04-09-2008
Message 4 of 7 (205 Views)

Re: How to create a good rectangle for a block with GeometricExtents

02-15-2013 05:40 AM in reply to: AubelecBE

Try to replace:

ext.TransformBy(Ed.CurrentUserCoordinateSystem.Inverse())

 

 with:

ext.TransformBy(RefBloc.BlockTransform.Inverse())

 


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Valued Mentor
AubelecBE
Posts: 387
Registered: ‎01-27-2010
Message 5 of 7 (176 Views)

Re: How to create a good rectangle for a block with GeometricExtents

02-18-2013 04:15 AM in reply to: Alexander.Rivilis

.. sorry, not working....

 

 

Moderator
Alexander.Rivilis
Posts: 1,406
Registered: ‎04-09-2008
Message 6 of 7 (173 Views)

Re: How to create a good rectangle for a block with GeometricExtents

02-18-2013 04:19 AM in reply to: AubelecBE

AubelecBE wrote:

.. sorry, not working....

 


Then I do not understand what you're trying to get. And what is the connection between GeometricExtents and UCS?


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Valued Mentor
AubelecBE
Posts: 387
Registered: ‎01-27-2010
Message 7 of 7 (160 Views)

Re: How to create a good rectangle for a block with GeometricExtents

02-19-2013 03:57 AM in reply to: Alexander.Rivilis

here a dwg sample.

 

The first BlockDefinition is generated on UCW  the second with UCS. --> The line is not egal ...

 

i show on the dwg the UCS i use for launch my command.

 

I have renamed the first blockdefinition . (My command reset the BlockDefinition is already exist in database)

 

++

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.