New Member
Posts: 1
Registered: ‎06-05-2006
Message 1 of 2 (257 Views)

Creating sphere using C# and SQL

257 Views, 1 Replies
06-05-2006 03:59 PM
I am trying to create a sphere by using C# pulling the values for location(x,y,z), radius, and color from a SQL DB. I can't seem to figure out how to generate my sphere anywhere but at the origin.
How can I move the location of my sphere to x,y,z.
Also, I noticed that Autodesk.AutoCAD.Geometry.Sphere has a constructor that allows you to specify a center but I then have problems adding it to the block table record.

Any suggestions would be greatly appreciated.

Here's the method I have so far:
public void createSphere(double x,double y,double z,double radius,int ci)
BlockTableRecord btr;
Transaction trans = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction();
Database db = HostApplicationServices.WorkingDatabase;

Solid3d sphere=new Solid3d();
sphere.ColorIndex = ci;
//I want to set center of sphere to x,y,z here

btr = (BlockTableRecord)trans.GetObject(HostApplicationServices.WorkingDatabase.CurrentSpaceId, OpenMode.ForWrite);
trans.AddNewlyCreatedDBObject(sphere, true);
Mick Duprez
Posts: 14
Registered: ‎11-19-2005
Message 2 of 2 (257 Views)

Re: Creating sphere using C# and SQL

06-05-2006 04:56 PM in reply to: DaveHB
You need to create a displacement vector of your insertion point then construct a matrix to transform (in this case translate) your object with.
This should help you get started -

Matrix3d mat = new Matrix3d();
mat = Matrix3d.Displacement(insertPnt.GetAsVector());//matrix is set to tranlation
sphere.TransformBy(mat);//translate your object:
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!