.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Please Help a Noob

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
312 Views, 4 Replies

Please Help a Noob

Hello,

I have several years experience with AutoCAD (about 25 years), and few years
of VB.NET programming (about 5 years) which is mostly web sites. I am now
trying to learn how to create custom commands and programs using VB.NET for
AutoCAD.

My first project is very simple. I have drawn 2 arcs, one offset from the
other. Now I would like to draw lines from the endpoint of 1 arc to the
other, essentially closing the object. I have code that works for drawing
the arcs, however I can't figure out how to draw the lines from the
endpoints. I'm figuring that I would need to draw a line from the start
point of arc1 to the start point of arc2, then another line from the end
point of arc1 to the end point of arc2. How do I get the start point and end
point of each arc?

Also, I have found
http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer%27s%20Guide/index.html
which is very helpful with examples; however I have a another other question
about programming AutoCAD.NET in general.

I know that you must start a transaction, open the block table for read,
then open the block record for write. After that, can I write more than one
object (i.e. line, arc, circle, etc.) to the block record before committing
the transaction? If this is possible, please provide some basic sample code.

Along with the web site above, what books, or other web sites, would you
recommend for a noob in AutoCAD.NET customization?

Thanks for the help,
James Walker
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

Hi James,

On the Forum, read down about 5 or 6 posts and I have asked about the same topic. But have narrowed my search. In the Autodesk Reference Material read up on the AutoCAD API topics and you will learn about Block Table Records and XData. Supposedly the EndPoint, StartPoint, MidPoint, Angle, CenterPoint, etc. is stored in Block Table Records which is supposedly contained in the SelectionSet for each object. Such as a line, an arc, a circle, etc.

I seem to have asked; How do I obtain a reference to a particular object and Get and Set the modified properties of objects? The properties are the EndPoint, StartPoint, etc...Code samples in the AutoCAD reference material allow you to select an object and the variable used in this code and the variable should be the reference to that object. But I keep getting an error indicating an incompatibility between a Geometry References and DataBase Services References. I am trying to get the EndPoint and StartPoint of a line so that I can use the AppendEntity Command to Break it by creating two new lines one with the Startpoint of the original line and a new endpoint (selected on screen) and then the other line with a new start point and the old endpoint of the original line.

I will let you know how I make out with this. I seem to have my thoughts organized and am working towards a solution in the proper direction. At least I think I am.

And if you do not mind visiting this post from time to time:

You can call me NoobA and I will call you NoobB....lol.

Golfy
Message 3 of 5
odoshi
in reply to: Anonymous

Hello James,

Arcs have StartPoint and EndPoint properties you can get.

Also, no need to open the block table for read, and then write. Just open it for write.

Check out the .NET samples in the ObjectARX SDK.

Regards,
Mike Caruso
Autodesk Certified Instructor 2014
AutoCAD/Civil 3D Autodesk Certified Professional 2014, 2015, 2018
www.whitemountaincad.com
Message 4 of 5
_gile
in reply to: Anonymous

Hi,

Here's a little sample adding two offseted arcs and the lines to close.
It's C#, but easy to convert to VB

{code}
[CommandMethod("Test")]
public void Test()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
Point3d center = new Point3d(5.0, 5.0, 0.0);
double ang45 = Math.PI * 0.25;
double ang135 = Math.PI * 0.75;
Arc arc1 = new Arc(center, 5.0, ang45, ang135);
Arc arc2 = new Arc(center, 6.0, ang45, ang135);
Line line1 = new Line(arc1.StartPoint, arc2.StartPoint);
Line line2 = new Line(arc1.EndPoint, arc2.EndPoint);
btr.AppendEntity(arc1);
tr.AddNewlyCreatedDBObject(arc1, true);
btr.AppendEntity(arc2);
tr.AddNewlyCreatedDBObject(arc2, true);
btr.AppendEntity(line1);
tr.AddNewlyCreatedDBObject(line1, true);
btr.AppendEntity(line2);
tr.AddNewlyCreatedDBObject(line2, true);
tr.Commit();
}
}{code}

You can replace:
{code}btr.AppendEntity(arc1);
tr.AddNewlyCreatedDBObject(arc1, true);
btr.AppendEntity(arc2);
tr.AddNewlyCreatedDBObject(arc2, true);
btr.AppendEntity(line1);
tr.AddNewlyCreatedDBObject(line1, true);
btr.AppendEntity(line2);
tr.AddNewlyCreatedDBObject(line2, true);{code}
by:
{code}Entity[] ents = { arc1, arc2, line1, line2 };
foreach (Entity ent in ents)
{
btr.AppendEntity(ent);
tr.AddNewlyCreatedDBObject(ent, true);
}{code}


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 5
Anonymous
in reply to: Anonymous

Thanks to everyone that has posted, I have learned alot from the information
provided.

James Walker

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost