.NET

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

Creating sphere using C# and SQL

243 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.
Thanks!

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
sphere.CreateSphere(radius);

btr = (BlockTableRecord)trans.GetObject(HostApplicationServices.WorkingDatabase.CurrentSpaceId, OpenMode.ForWrite);
btr.AppendEntity(sphere);
trans.AddNewlyCreatedDBObject(sphere, true);
trans.Commit();
trans.Dispose();
}
Contributor
Mick Duprez
Posts: 14
Registered: ‎11-19-2005
Message 2 of 2 (243 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:

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
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

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

Ask the Community