Problem in drawing sphere...

Problem in drawing sphere...

Anonymous
Not applicable
664 Views
5 Replies
Message 1 of 6

Problem in drawing sphere...

Anonymous
Not applicable
I am trying to draw Sphere but it is giving me error;

{code}
using (tran = db.TransactionManager.StartTransaction())
{
try
{
BlockTable bt = (BlockTable)tran.GetObject(db.BlockTableId,OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tran.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
Solid3d s = new Solid3d();

//Rectangle3d rec = new Rectangle3d(new Point3d(10, 20, 0), new Point3d(20, 20, 0), new Point3d(10, 0, 0), new Point3d(20, 10, 0));
Sphere sph = new Sphere(5, new Point3d(10, 10, 0), Vector3d.ZAxis, Vector3d.XAxis, 0, 360, 0, 360);
btr.AppendEntity(sph);
tran.AddNewlyCreatedDBObject(sph, true);
tran.Commit();
}

catch(Autodesk.AutoCAD.Runtime.Exception ex)
{
editor.WriteMessage("\nAutoCAD >>" + ex.Message);
}
catch(System.Exception ex)
{
editor.WriteMessage("\nSystem >>" + ex.Message);
}
}
{code}
0 Likes
665 Views
5 Replies
Replies (5)
Message 2 of 6

chiefbraincloud
Collaborator
Collaborator
The sphere object you are declaring as sph comes from the Geometry namespace, and does not inherit the Entity class, and so can not be appended to a block table record (or added to the transaction I believe).

You need to use your Solid3D object "s" and call s.CreateSphere (Radius)

Then in order to position it in space, you would call s.TranslateBy(TranslationMatrix)

Then you can btr.AppendEntity(s)

and Tran.AddNewlyCreatedDBObject(s, true)
Dave O.                                                                  Sig-Logos32.png
0 Likes
Message 3 of 6

Anonymous
Not applicable
i want to put Solid object (Sphere) to user specific position but Sphere is locating at 0,0,0. why?
how to use transformBy(Matrix3d transform);

Solid3d s = new Solid3d();
s.CreateSphere(10.0);
btr.AppendEntity(s);
tran.AddNewlyCreatedDBObject(s,true);

thanks
0 Likes
Message 4 of 6

Hallex
Advisor
Advisor
Use GetAsVector method:

Dim sol As Solid3d = New Solid3d
sol.CreateSphere(rad)
Dim ptOpts As PromptPointOptions = New PromptPointOptions( _
"\nPick a center point of sphere: ")
Dim ptRes As PromptPointResult = _
ed.GetPoint(ptOpts)
If ptRes.Status <> PromptStatus.OK Then
Return
End If
Dim topt As Point3d = ptRes.Value
Dim mat As Matrix3d = Matrix3d.Displacement(topt.GetAsVector())
sol.TransformBy(mat)
btr.AppendEntity(sol)
tr.AddNewlyCreatedDBObject(sol, True)
tr.Commit()

~'J'~
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes
Message 5 of 6

Anonymous
Not applicable
thanks for your information.

in C# Cylinder, Sphere, Cone as they are not inherited from Entity.
How we can use them if any one wants to use. Becoz when i use Solid3D.createSphere i never get the center of sphere OR i cant set its position.


thanks. Edited by: FergiPune on Feb 11, 2009 6:23 AM
0 Likes
Message 6 of 6

Anonymous
Not applicable
The sphere is created at the WCS origin, so you have to
use TransformBy() to get it into the orientation and position
you need.

Unfortunately, 3D API functionality is deliberately hobbled
and limited in AutoCAD, so it can't be used by customers
to build solutions that are competitive with Inventor, et. al.

--
http://www.caddzone.com

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

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


wrote in message news:6122403@discussion.autodesk.com...
thanks for your information. in C# Cylinder, Sphere, Cone as they are not
inherited from Entity. How we can use them if any one wants to use. Becoz
when i use Solid3D.createSphere i never get the center of sphere OR i cant
set its position. thanks. Edited by: FergiPune on Feb 11, 2009 6:23 AM
0 Likes