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

Creating sphere using C# and SQL

1 REPLY 1
Reply
Message 1 of 2
DaveHB
965 Views, 1 Reply

Creating sphere using C# and SQL

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();
}
1 REPLY 1
Message 2 of 2
Mick Duprez
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:

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