.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
How can I use a graphic ellipse with text together?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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!
Solved! Go to Solution.
Re: How can I use a graphic ellipse with text together?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi Kevin,
Do you want to create the block with one attribute inside the ellipse?
C6309D9E0751D165D0934D0621DFF27919
Re: How can I use a graphic ellipse with text together?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.D ocumentManager.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(Color Method.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(Color Method.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
Re: How can I use a graphic ellipse with text together?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Thanks for your repy.If the attribute can show and edit on the paper , It is maybe perfect.
I will try your code.
Re: How can I use a graphic ellipse with text together?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.D ocumentManager.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(Color Method.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(Color Method.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
Re: How can I use a graphic ellipse with text together?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.
Re: How can I use a graphic ellipse with text together?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
In this case discard show dialog using ATTDIA variable, see Help file
Cheers ![]()
C6309D9E0751D165D0934D0621DFF27919
Re: How can I use a graphic ellipse with text together?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Can you tell me a more detailed method? Do you mean that when editing the attribute, the dialogue also does not appear ?
Re: How can I use a graphic ellipse with text together?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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!
Re: How can I use a graphic ellipse with text together?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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


