.NET

Reply
*Nermeen Bakr
Message 1 of 5 (883 Views)

How to draw a cylinder using vb.net

883 Views, 4 Replies
07-20-2005 08:06 AM
Hi:
I want to draw a 3d cylinder through the origion point raduis
path(axis),height or the start point and end point of the center axis of the
cylinder
I found the cylinder object as a member of the geometry elements but i don't
know how could i add this cylinder thpe to the drawing database as i could
see it in the drawing.

Thanks in advance.

--
Nermeen Bakr
Project Manager
MCS (Modern Computing Services)
Website: http://www.mcsoil.com
Phone: +2 02 4036520 /+202 4051129
Fax: +2 02 4040503
Distinguished Contributor
Posts: 219
Registered: ‎05-25-2004
Message 2 of 5 (883 Views)

Re: How to draw a cylinder using vb.net

12-05-2007 05:01 AM in reply to: *Nermeen Bakr
I'm struggling with this too:

Imports Autodesk.AutoCAD
'Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.ApplicationServices

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myTransMan As DatabaseServices.TransactionManager
Dim myTrans As DatabaseServices.Transaction
Dim myDWG As Document
Dim myBT As BlockTable
Dim myBTR As BlockTableRecord
Dim myCylinder As Cylinder
Dim StartPoint As Geometry.Point3d
Dim EndPoint As Geometry.Point3d

myDWG = Application.DocumentManager.MdiActiveDocument
myTransMan = myDWG.TransactionManager
myTrans = myTransMan.StartTransaction

'open database for read
myBT = myDWG.Database.BlockTableId.GetObject(OpenMode.ForRead)

'open ModelSpace for write
myBTR = myBT(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)

StartPoint = myDWG.Editor.GetPoint("Select Start Point: ").Value
EndPoint = myDWG.Editor.GetPoint("Select End Point: ").Value

'create the cylinder
myCylinder = New Cylinder(7.723, StartPoint, EndPoint)
'Add cylinder to Modelspaces block table record
myBTR.AppendEntity(myCylinder)
'Add cylinder to the transaction
myTrans.AddNewlyCreatedDBObject(myCylinder, True)
'commit transaction
myTrans.Commit()
'dispose transaction
myTrans.Dispose()
myTransMan.Dispose()

End Sub
*Tony Tanzillo
Message 3 of 5 (883 Views)

Re: How to draw a cylinder using vb.net

12-05-2007 05:42 AM in reply to: *Nermeen Bakr
I'm not going to comment on this, other than to say that you need to learn how to structure your app, as it relates to acquiring user input, and accessing the database.

Generally, you acquire all user input before you access the database or its contents, where that's possible. Once you've obtained the needed input successfully, only then do you start a transaction
and open objects.

Read the ObjectARX docs, and note where they discuss the patterns relating to opening and closing objects, and how you should keep objects open only as long as absolutely necessary and close them as soon as possible.

What you definitely should not do is open an object for write, and then acquire input. The chances that AutoCAD or another application may try to open an object while getting user input (e.g., for things like object snap, etc.), are very good, and in that case, if an object or one of its owners is currently open for write, kaboom.

--
http://www.caddzone.com

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

wrote in message news:5792878@discussion.autodesk.com...
I'm struggling with this too:

Imports Autodesk.AutoCAD
'Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.ApplicationServices

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myTransMan As DatabaseServices.TransactionManager
Dim myTrans As DatabaseServices.Transaction
Dim myDWG As Document
Dim myBT As BlockTable
Dim myBTR As BlockTableRecord
Dim myCylinder As Cylinder
Dim StartPoint As Geometry.Point3d
Dim EndPoint As Geometry.Point3d

myDWG = Application.DocumentManager.MdiActiveDocument
myTransMan = myDWG.TransactionManager
myTrans = myTransMan.StartTransaction

'open database for read
myBT = myDWG.Database.BlockTableId.GetObject(OpenMode.ForRead)

'open ModelSpace for write
myBTR = myBT(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)

StartPoint = myDWG.Editor.GetPoint("Select Start Point: ").Value
EndPoint = myDWG.Editor.GetPoint("Select End Point: ").Value

'create the cylinder
myCylinder = New Cylinder(7.723, StartPoint, EndPoint)
'Add cylinder to Modelspaces block table record
myBTR.AppendEntity(myCylinder)
'Add cylinder to the transaction
myTrans.AddNewlyCreatedDBObject(myCylinder, True)
'commit transaction
myTrans.Commit()
'dispose transaction
myTrans.Dispose()
myTransMan.Dispose()

End Sub
Distinguished Contributor
Posts: 219
Registered: ‎05-25-2004
Message 4 of 5 (883 Views)

Re: How to draw a cylinder using vb.net

12-05-2007 05:58 AM in reply to: *Nermeen Bakr
Thank you for your comments Tony. I have only been looking at .Net for a few weeks in my lunch half hour (wish I had an hour - grrr!). I am using the code from pages 59 & 69 of Jerry Winter's VB.Net book. I find it useful to work through his exercises then to try and adapt them for something that I can use in my job.

In his example he accesses the database thingy first then gets user input and creates the entity.

Guess I'm just trying to pass the buck!
*Tony Tanzillo
Message 5 of 5 (883 Views)

Re: How to draw a cylinder using vb.net

12-05-2007 06:21 AM in reply to: *Nermeen Bakr
Let me apologize in advance to anyone that may be offended by this, but I have tell you that if you got that code from a book, I would have no choice but to give that book a big thumbs down, regardless of who wrote/published/edited it.

Sorry again. Books are things that people write when they have expertise to share, and those who pay them money for their work have a right to hold the author(s), publisher, and technical editor(s) accountable for inacurracies and/or technically flawed or inferior content, within the domain of expertise.

If you're serious about this, consider Autodesk API training, as their instructors are qualified and know what they're doing.

--
http://www.caddzone.com

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

wrote in message news:5792924@discussion.autodesk.com...
Thank you for your comments Tony. I have only been looking at .Net for a few weeks in my lunch half hour (wish I had an hour - grrr!). I am using the code from pages 59 & 69 of Jerry Winter's VB.Net book. I find it useful to work through his exercises then to try and adapt them for something that I can use in my job.

In his example he accesses the database thingy first then gets user input and creates the entity.

Guess I'm just trying to pass the buck!

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community