.NET

Reply
Active Contributor
brianaubert
Posts: 38
Registered: ‎03-22-2005
Message 1 of 8 (384 Views)
Accepted Solution

Dimension Association with VB

384 Views, 7 Replies
06-19-2012 11:27 AM

Hi All,

 

How do you Associate a dimension to a line using VB. I have not had any results searching for an example of this.

 

Thank you,

Brian

Ok, I understand, but to create extension dictionary to set associativity

will be spend a lot of work

 

Here is simple way:

 [CommandMethod("assocdim")]
public void CreateAssocDim()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptEntityOptions peo = new PromptEntityOptions("\nSelect line: ");
peo.SetRejectMessage("\nYou have to select line only!");
peo.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Line), true);
PromptEntityResult res = ed.GetEntity(peo);
if (res.Status != PromptStatus.OK) return;
ObjectId id = res.ObjectId;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
try
{
Autodesk.AutoCAD.DatabaseServices.Line ln = trans.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Line;
Point3d p1 = ln.StartPoint;
Point3d p2 = ln.EndPoint;
Point3d txpt = p1;
Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("dimassoc", 2);
doc.SendStringToExecute("_dimlinear end " + p1.X.ToString() + "," + p1.Y.ToString() + "," + p1.Z.ToString() +
" end " + p2.X.ToString() + "," + p2.Y.ToString() + "," + p2.Z.ToString() + " " +
txpt.X.ToString() + " " + txpt.Y.ToString() + "," + txpt.Z.ToString() + " ", true, false, false);
trans.Commit();
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}

 If this is not enough so  say me about

 

~'J'~

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

Re: Dimension Association with VB

06-19-2012 12:27 PM in reply to: brianaubert

Take a look at this code, not sure about if this helps, though

 http://forums.autodesk.com/autodesk/attachments/autodesk/152/24647/1/Parametric%20VB%20Net%20Code.tx...)

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Active Contributor
brianaubert
Posts: 38
Registered: ‎03-22-2005
Message 3 of 8 (369 Views)

Re: Dimension Association with VB

06-19-2012 12:45 PM in reply to: brianaubert

Thanks for the response Hallex. I'll take a look at that.

 

I'm not looking for parametrics, just normal entities and associative dimensions.

 

I came across a post about reactors and using LISP, that I'm currently trying to hack something together in VB to operate with reactors. I'm not sure how this will turn out though.

 

Brian

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

Re: Dimension Association with VB

06-19-2012 02:00 PM in reply to: brianaubert

Ok, I understand, but to create extension dictionary to set associativity

will be spend a lot of work

 

Here is simple way:

        [CommandMethod("assocdim")]
        public void CreateAssocDim()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            PromptEntityOptions peo = new PromptEntityOptions("\nSelect line: ");
            peo.SetRejectMessage("\nYou have to select line only!");
            peo.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Line), true);
            PromptEntityResult res = ed.GetEntity(peo);
            if (res.Status != PromptStatus.OK) return;
            ObjectId id = res.ObjectId;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                try
                {

                    Autodesk.AutoCAD.DatabaseServices.Line ln = trans.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Line;
                    Point3d p1 = ln.StartPoint;
                    Point3d p2 = ln.EndPoint;
                    Point3d txpt = p1;

                    Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("dimassoc", 2);

                    doc.SendStringToExecute("_dimlinear end " + p1.X.ToString() + "," + p1.Y.ToString() + "," + p1.Z.ToString() +
                        " end " + p2.X.ToString() + "," + p2.Y.ToString() + "," + p2.Z.ToString() + " " +
                            txpt.X.ToString() + " " + txpt.Y.ToString() + "," + txpt.Z.ToString() + " ", true, false, false);


                    trans.Commit();
                }

                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }

 If this is not enough so  say me about

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Valued Mentor
jeff
Posts: 338
Registered: ‎05-12-2009
Message 5 of 8 (352 Views)

Re: Dimension Association with VB

06-19-2012 04:23 PM in reply to: Hallex

Does setting the DIMASSOC variable do wht you need?

You can also find your answers @ TheSwamp
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 6 of 8 (341 Views)

Re: Dimension Association with VB

06-19-2012 09:22 PM in reply to: jeff

Hi Jeff

The DIMASSOC variable doesn't affect creation of the associative dimension

usual way, unfortunately

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Active Contributor
brianaubert
Posts: 38
Registered: ‎03-22-2005
Message 7 of 8 (335 Views)

Re: Dimension Association with VB

06-20-2012 06:07 AM in reply to: brianaubert

Thank you Hallex !

 

As you already know, I'm sure, that worked.

 

Nice and simple.

 

I've read many of your other posts to peoples questions and pick up on many things. Your a good guy to have on here.

 

I've been with Autocad since v2.17 and have programed with it extensively, but this .Net stuff is a real challenge to get the hang of.

 

Makes me feel like a Knob / Newbie again.

 

Thanks,

Brian

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

Re: Dimension Association with VB

06-20-2012 06:25 AM in reply to: brianaubert

Brian, thanks for your warm words

I'm happy if I can help,

Happy coding :smileyhappy:

 

~'J'~

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