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

Drawing a Rectangle

10 REPLIES 10
Reply
Message 1 of 11
Saumitra
2123 Views, 10 Replies

Drawing a Rectangle

Hi:

I am trying to draw a rectangle, given the 4 coordinates of the rectangle. I was basing my code on the lab tutorials for Cad 2007 where there is a description about drawing a circle.

bt = trans.GetObject(db.BlockTableId, OpenMode.ForWrite)
btrId = bt.Item(BlockTableRecord.ModelSpace)
btr = trans.GetObject(btrId, OpenMode.ForWrite)

rect = New Rectangle3d(ptTopLeft, ptTopRight, ptBottomLeft, ptBottomRight)
btr.AppendEntity(rect)
trans.AddNewlyCreatedDBObject(rect, True)

However, I am getting an error in the last 2 lines. The reason I presume is that Rectangle3d is a structure in the library. And the methods take DatabaseServices.Entity types as parameter. The code in the tutorial worked for circle/ellipse coz they are defined as classes.

Am I correct in my assumption and how can this be corrected? I have tried type-casting but that does not work either.

Thanks

Saumitra
10 REPLIES 10
Message 2 of 11
Anonymous
in reply to: Saumitra

I'm not sure how you came up with the assumption
there's a 'Rectangle3d' class, but there's none.

There's no 'rectangle' object in AutoCAD, hence
there's no corresponding class.

The RECTANG command draws a 4-segment
polyline, not a 'RECTANGLE' object.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5789864@discussion.autodesk.com...
Hi:

I am trying to draw a rectangle, given the 4 coordinates of the rectangle. I was basing my code on the lab tutorials for Cad 2007 where there is a description about drawing a circle.

bt = trans.GetObject(db.BlockTableId, OpenMode.ForWrite)
btrId = bt.Item(BlockTableRecord.ModelSpace)
btr = trans.GetObject(btrId, OpenMode.ForWrite)

rect = New Rectangle3d(ptTopLeft, ptTopRight, ptBottomLeft, ptBottomRight)
btr.AppendEntity(rect)
trans.AddNewlyCreatedDBObject(rect, True)

However, I am getting an error in the last 2 lines. The reason I presume is that Rectangle3d is a structure in the library. And the methods take DatabaseServices.Entity types as parameter. The code in the tutorial worked for circle/ellipse coz they are defined as classes.

Am I correct in my assumption and how can this be corrected? I have tried type-casting but that does not work either.

Thanks

Saumitra
Message 3 of 11
Saumitra
in reply to: Saumitra

Well, I didnt assume that there was the Rectangle3d class.
There is a structure at
autodesk.AutoCAD.DatabaseServices.Rectangle3d

And also a structure called Rectangle...

I thought (given the name of the structure, it wasn't very presumptuous to give it a try) it would be the one to draw a rectangle. So, the only way to draw a rectangle is through the RECTANG command?

Saumitra
Message 4 of 11
Anonymous
in reply to: Saumitra

>> Well, I didnt assume that there was the Rectangle3d class.

What I meant was that you assumed there was
a formal AutoCAD entity type 'rectangle', not that
there was a class for it.

As I said, there is no entity type corresponding
to a rectangle.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5790667@discussion.autodesk.com...
Well, I didnt assume that there was the Rectangle3d class.
There is a structure at
autodesk.AutoCAD.DatabaseServices.Rectangle3d

And also a structure called Rectangle...

I thought (given the name of the structure, it wasn't very presumptuous to give it a try) it would be the one to draw a rectangle. So, the only way to draw a rectangle is through the RECTANG command?

Saumitra
Message 5 of 11
Saumitra
in reply to: Saumitra

So, Tony is this a proper way to draw a rectangle then.

strCommand = "RECTANG" & ptBottomLeft.ToString & ptTopRight.ToString

acadDoc.SendStringToExecute(strCommand, True, False, True)

acadDoc is the current document. This one is not working. Am i on the wrong track and just try drawing a rectangle through 4 polylines?

Saumitra
Message 6 of 11
Anonymous
in reply to: Saumitra

>> So, the only way to draw a rectangle is through
>> the RECTANG command?

I'll be happy to answer you, if you can first tell me if
you're new to AutoCAD and/or AutoCAD development.

I think you already know that this is something you
should make clear, so that others can give you an
answer in terms that you can understand, and not
make the mistake of presuming that you already
have a grasp of other more basic concepts that any
helpful answer would depend on.

The fact that you're asking the above question would
suggest that you've not done much AutoCAD work,
which is fine, so long as you make that clear at the
outset.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5790667@discussion.autodesk.com...
Well, I didnt assume that there was the Rectangle3d class.
There is a structure at
autodesk.AutoCAD.DatabaseServices.Rectangle3d

And also a structure called Rectangle...

I thought (given the name of the structure, it wasn't very presumptuous to give it a try) it would be the one to draw a rectangle. So, the only way to draw a rectangle is through the RECTANG command?

Saumitra
Message 7 of 11
Saumitra
in reply to: Saumitra

Well, I am extremely new to AutoCAD (let alone autocad development). Anyways, I have managed to create a rectangle through polylines. If for my knowledge purpose, you can answer what I asked earlier, it would be great. Next time onwards, I would specify what is required to mention in the email.
Message 8 of 11
Mikko
in reply to: Saumitra

Here's a few lines that will draw a 3d solid rectangle that might be of help.

Dim db As Database = HostApplicationServices.WorkingDatabase
Using t As Transaction = db.TransactionManager.StartTransaction()
Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
Dim bt As BlockTable = CType(t.GetObject(db.BlockTableId, OpenMode.ForRead, False), BlockTable)
Dim btr As BlockTableRecord = CType(t.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite, False), BlockTableRecord)
Dim r3d As New Solid3d
r3d.CreateBox(5.0, 2.0, 10.0)
btr.AppendEntity(r3d)
t.AddNewlyCreatedDBObject(r3d, True)
t.Commit()
End Using
Message 9 of 11
Anonymous
in reply to: Saumitra

You can create polylines directly, without having to use the command line interface, but of course, that's a bit more involved than the 'easy' way (e.g., using the command line).

You use the Polyline class (call the constructor), and then set the properties to what you want and add the vertices, then add it to the database and to the block table record for the space you're drawing in.

Doing it that way does require some experience with the API, so if you are writing a real application that needs to draw rectangles, you can use the command line (or the ActiveX API) until you are able to use the more direct method.

Look at the code posted here and at the links posted here, for useful examples of using the API directly to create and work with AutoCAD objects.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5790800@discussion.autodesk.com...
Well, I am extremely new to AutoCAD (let alone autocad development). Anyways, I have managed to create a rectangle through polylines. If for my knowledge purpose, you can answer what I asked earlier, it would be great. Next time onwards, I would specify what is required to mention in the email.
Message 10 of 11
nlvvch
in reply to: Saumitra

Hi, soumitra

there is no rectangle class, there is only line, polyline and lwpolyline only. so u try it as polyline are lwpolyline


venkatesh
venkatesh.chitimilla@regencyinfotech.biz
regency infotech
Message 11 of 11
Saumitra
in reply to: Saumitra

Thanks everybody for your help. The code for drawing a rectangle through a Solid3d class was also helpful.

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