Cad. NET adjust the text width in a property block

Source: Internet
Author: User

Using System;
Using Autodesk.AutoCAD.ApplicationServices;
Using Autodesk.AutoCAD.DatabaseServices;
Using Autodesk.AutoCAD.EditorInput;
Using Autodesk.AutoCAD.Geometry;
Using Autodesk.AutoCAD.Runtime;

[Assembly:commandclass (typeof (Attributewidthfactor.mycommands))]

Namespace Attributewidthfactor
{
public class Mycommands
{
[Commandmethod ("Attwidth")]
public static void Setattrwidthfactor ()
{
Document dwg = Application.DocumentManager.MdiActiveDocument;
Editor ed = dwg. Editor;

Pick an attributereference in a block
Promptnestedentityoptions opt = new
Promptnestedentityoptions ("\npick an attribute:");
Promptnestedentityresult res = ed. Getnestedentity (opt);

if (res. Status = = Promptstatus.ok)
{
if (res. ObjectId.ObjectClass.DxfName.ToUpper () = = "ATTRIB")
{
Ask user to pick a distance as desired width for
The attribute to fit in. Based on the block, the width
Could be a known value
Promptpointoptions popt = new
Promptpointoptions ("\npick width base point:");
Promptpointresult pres = ed. GetPoint (popt);
if (pres. Status! = Promptstatus.ok) return;
Point3D basept = pres. Value;

Promptdistanceoptions dopt =
New Promptdistanceoptions ("\npick width:");
Dopt. Usebasepoint = true;
Dopt. Basepoint = basept;

Promptdoubleresult dres = ed. Getdistance (dopt);
if (Dres. Status! = Promptstatus.ok) return;

This is the width of we want to fit the attribute text ' s width
Double w = dres. Value;

using (Transaction tran =
Dwg. Transactionmanager.starttransaction ())
{
Attributereference att = (attributereference) tran. GetObject (
Res. ObjectId, Openmode.forwrite);

Get attribute ' s width, assuming it is placed horizontally
Double aw = Math.Abs (att. Geometricextents.maxpoint.x
-Att. Geometricextents.minpoint.x);

The Widthfactor
Double factor = W/aw;
Att. Widthfactor = factor;

Tran.commit ();
}
}
Else
{
Application.showalertdialog ("Not an attribute!");
}
}
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.