.NET

.NET

Reply
Valued Contributor
kevinsir
Posts: 78
Registered: ‎08-20-2012
Message 1 of 19 (508 Views)
Accepted Solution

How can I use a graphic ellipse with text together?

508 Views, 18 Replies
03-15-2013 08:24 PM

Hello, everyone

I want to create a new order. when  using the order,It will create a  ellipse and  a DTEXT .I mean the ellipse and the DTEXT are a whole. when move the ellipse the DTEXT will alse move.However, users can  edit the  DTEXT.

Someone who can give  me some solution? Thanks very much!

Hi Kevin,

Do you want to create the block with one attribute inside the ellipse?

I am sorry that I mean the AttributeReference! Now I have find the 'AttributeCollection' Property of BlockReference which can access the Attribute. However, I have not find any Property of BlockReference to access the ellipse. Does it have any way to access it and set it visible or invisible?

kevinsir wrote:
...However, I have not find any Property of BlockReference to access the ellipse. Does it have any way to access it and set it visible or invisible?...

Ellipse is a part of BlockTableRecord and not part of BlockReference. You can have access to ellipse in BlockTableRecord and set it visible or invisible. But that setting will effect ALL BlockReference created from this BlockTableRecord (after regeneration of drawing).  If you create dynamic block you can manipulate property Visibility to hide/unhide ellipse and text individually in each BlockReference. Look at attached dwg-file.

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 19 (478 Views)

Re: How can I use a graphic ellipse with text together?

03-16-2013 07:49 AM in reply to: kevinsir

Hi Kevin,

Do you want to create the block with one attribute inside the ellipse?

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 19 (472 Views)

Re: How can I use a graphic ellipse with text together?

03-16-2013 08:39 AM in reply to: kevinsir

Though you could be read same code in Labs,

here is quick example

    [CommandMethod("OrderBlock", CommandFlags.Modal | CommandFlags.Redraw)]
        public static void CreateOrderLabel()
        {
            // Get the current document and database
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

            Database db = doc.Database;

            Editor ed = doc.Editor;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForWrite);

                    // get current text size for attribute or use hard coded one instead
                    double txtheight = db.Textsize;
                    // block name
                    string blkName = "ORDER";
                    // check if exists
                    if (bt.Has(blkName))
                    {
                        ed.WriteMessage("\nBlock \"ORDER\" already exist.");
                        return;// if exists then exit
                    }
                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                    Point3d inspt = new Point3d(0, 0, 0);
                    BlockTableRecord newBtr = new BlockTableRecord();
                    bt.Add(newBtr);

                    // change settings for you block to your suit:
                    newBtr.Name = blkName;
                    newBtr.Origin = inspt;
                    newBtr.BlockScaling = BlockScaling.Uniform;
                    newBtr.Units = UnitsValue.Inches;
                    newBtr.Explodable = false;
                    tr.AddNewlyCreatedDBObject(newBtr, true);

                    Vector3d normal = Vector3d.ZAxis;
                    Vector3d majorAxis = 6 * txtheight * Vector3d.XAxis;// change major axis to your suit
                    double radiusRatio = 0.4;// change ratio to your suit
                    double startAng = 0.0;
                    double endAng = Math.PI * 2;
                    Ellipse ellipse = new Ellipse(inspt, normal, majorAxis, radiusRatio, startAng, endAng);
                    ellipse.Layer = "0";
                    ellipse.LinetypeId = db.ContinuousLinetype;
                    ellipse.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, 0);// color by block
                    ellipse.LineWeight = LineWeight.LineWeight040;// wide lineweight 0.40, change on LineWeight.ByLineWeightDefault to discard it
                    newBtr.AppendEntity(ellipse);
                    tr.AddNewlyCreatedDBObject(ellipse, true);

                    AttributeDefinition attr = new AttributeDefinition();
                    attr.Layer = "0";
                    attr.LinetypeId = db.ContinuousLinetype;
                    attr.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, 0);// color by block
                    attr.LineWeight = LineWeight.ByLineWeightDefault;
                    attr.Tag = "DESCRIPTION";
                    attr.Prompt = "Order description:";
                    attr.TextString = "blah";
                    attr.Preset = true;

                    //attr.TextStyle = db.Textstyle;//<--   A2009
                    attr.TextStyleId = db.Textstyle;//<--   A2010
                    attr.Height = txtheight;
                    attr.Position = inspt;
                    attr.Justify = AttachmentPoint.MiddleCenter;
                    attr.AlignmentPoint = inspt;
                    attr.LockPositionInBlock = true;
                    attr.AdjustAlignment(db);
                    newBtr.AppendEntity(attr);
                    tr.AddNewlyCreatedDBObject(attr, true);

                    tr.Commit();
                    ed.Regen();
                }
                catch (Autodesk.AutoCAD.Runtime.Exception ex)
                {
                    ed.WriteMessage(ex.Message + "\n" + ex.StackTrace);
                }
            }
        }

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Valued Contributor
kevinsir
Posts: 78
Registered: ‎08-20-2012
Message 4 of 19 (468 Views)

Re: How can I use a graphic ellipse with text together?

03-16-2013 08:57 AM in reply to: kevinsir

Thanks for your repy.If the attribute can show  and edit on the paper , It is maybe perfect.

I will try your code.

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 5 of 19 (462 Views)

Re: How can I use a graphic ellipse with text together?

03-16-2013 09:54 AM in reply to: kevinsir

Here is VB.NET code,see my poor comments inline

        <CommandMethod("OrderBlock", CommandFlags.Modal Or CommandFlags.Redraw)> _
        Public Shared Sub CreateOrderLabel()
            ' Get the current document and database
            Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

            Dim db As Database = doc.Database

            Dim ed As Editor = doc.Editor

            Using tr As Transaction = db.TransactionManager.StartTransaction()
                Try
                    Dim bt As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForWrite), BlockTable)

                    ' get current text size for attribute or use hard coded one instead
                    Dim txtheight As Double = db.Textsize
                    ' block name
                    Dim blkName As String = "ORDER"
                    ' check if exists
                    If bt.Has(blkName) Then
                        ed.WriteMessage(vbLf & "Block ""ORDER"" already exist.")
                        ' if exists then exit
                        Return
                    End If
                    Dim btr As BlockTableRecord = DirectCast(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
                    Dim inspt As New Point3d(0, 0, 0)
                    Dim newBtr As New BlockTableRecord()
                    bt.Add(newBtr)

                    ' change settings for you block to your suit:
                    newBtr.Name = blkName
                    newBtr.Origin = inspt
                    newBtr.BlockScaling = BlockScaling.Uniform
                    newBtr.Units = UnitsValue.Inches
                    newBtr.Explodable = False
                    tr.AddNewlyCreatedDBObject(newBtr, True)

                    Dim normal As Vector3d = Vector3d.ZAxis
                    Dim majorAxis As Vector3d = 6 * txtheight * Vector3d.XAxis
                    ' change major axis to your suit
                    Dim radiusRatio As Double = 0.4
                    ' change ratio to your suit
                    Dim startAng As Double = 0.0
                    Dim endAng As Double = Math.PI * 2
                    Dim ellipse As New Ellipse(inspt, normal, majorAxis, radiusRatio, startAng, endAng)
                    ellipse.Layer = "0"
                    ellipse.LinetypeId = db.ContinuousLinetype
                    ellipse.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, 0)
                    ' color by block
                    ellipse.LineWeight = LineWeight.LineWeight040
                    ' wide lineweight 0.40, change on LineWeight.ByLineWeightDefault to discard it
                    newBtr.AppendEntity(ellipse)
                    tr.AddNewlyCreatedDBObject(ellipse, True)

                    Dim attr As New AttributeDefinition()
                    attr.Layer = "0"
                    attr.LinetypeId = db.ContinuousLinetype
                    attr.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, 0)
                    ' color by block
                    attr.LineWeight = LineWeight.ByLineWeightDefault
                    attr.Tag = "DESCRIPTION"
                    attr.Prompt = "Order description:"
                    attr.TextString = "blah"
                    attr.Preset = True
                    ' using current textstyle
                    'attr.TextStyle = db.Textstyle ''<--   A2009
                    attr.TextStyleId = db.Textstyle ''<--   A2010
                    attr.Height = txtheight
                    attr.Position = inspt
                    attr.Justify = AttachmentPoint.MiddleCenter
                    attr.AlignmentPoint = inspt
                    attr.LockPositionInBlock = True
                    attr.AdjustAlignment(db)
                    newBtr.AppendEntity(attr)
                    tr.AddNewlyCreatedDBObject(attr, True)

                    tr.Commit()
                    ed.Regen()
                Catch ex As Autodesk.AutoCAD.Runtime.Exception
                    ed.WriteMessage(ex.Message + vbLf + ex.StackTrace)
                End Try
            End Using
        End Sub

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Valued Contributor
kevinsir
Posts: 78
Registered: ‎08-20-2012
Message 6 of 19 (450 Views)

Re: How can I use a graphic ellipse with text together?

03-16-2013 08:48 PM in reply to: Hallex

Thanks a lot ! It is a nice solution. However, is there any better idea that if i want to edit description on the screen directly,never show a description dialogue.Because my customers use CAD on the pad ,maybe they want a big input UI.

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 7 of 19 (443 Views)

Re: How can I use a graphic ellipse with text together?

03-16-2013 11:25 PM in reply to: kevinsir

In this case discard show dialog using ATTDIA variable, see Help file

Cheers :smileyhappy:

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Valued Contributor
kevinsir
Posts: 78
Registered: ‎08-20-2012
Message 8 of 19 (441 Views)

Re: How can I use a graphic ellipse with text together?

03-17-2013 12:19 AM in reply to: Hallex

Can you tell me a more detailed method? Do  you mean that  when editing the attribute,  the dialogue also does not  appear ? 

Valued Contributor
kevinsir
Posts: 78
Registered: ‎08-20-2012
Message 9 of 19 (433 Views)

Re: How can I use a graphic ellipse with text together?

03-17-2013 04:25 AM in reply to: kevinsir

I mean can I  use this attribute like dbtext,

and another question is that is therer any setting i can set the attibute or the ellipse to be  visible or invisible!

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 10 of 19 (426 Views)

Re: How can I use a graphic ellipse with text together?

03-17-2013 06:03 AM in reply to: kevinsir

I have not have a time for testing and could not reach at AutoCAD now,

but you can play with attribite mode,

say specify your settings instead, e.g. in this line of code:

attr.Preset = True

You may want to play with something like

attr.Verify=true, same for Visible etc

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.