• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Mentor
    Posts: 260
    Registered: ‎01-27-2010

    How to create a good rectangle for a block with GeometricExtents

    218 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

    Please use plain text.
    ADN Support Specialist
    Posts: 202
    Registered: ‎06-02-2009

    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

    Please use plain text.
    Mentor
    Posts: 260
    Registered: ‎01-27-2010

    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.

     

     

    Please use plain text.
    Moderator
    Alexander.Rivilis
    Posts: 1,178
    Registered: ‎04-09-2008

    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

    Please use plain text.
    Mentor
    Posts: 260
    Registered: ‎01-27-2010

    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....

     

     

    Please use plain text.
    Moderator
    Alexander.Rivilis
    Posts: 1,178
    Registered: ‎04-09-2008

    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

    Please use plain text.
    Mentor
    Posts: 260
    Registered: ‎01-27-2010

    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)

     

    ++

    Please use plain text.