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

Creating sphere using C# and SQL

263 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 (263 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
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.