how to assigning centroid for Box

how to assigning centroid for Box

almutaz_86
Advocate Advocate
428 Views
2 Replies
Message 1 of 3

how to assigning centroid for Box

almutaz_86
Advocate
Advocate

Good Evening 
I'm new to AutoCAD .NET API  ,and trying to create simple code to create box, and its worked.

but AutoCAD put the centroid of the box in 0,0,0 

How to change it

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;

[assembly:ExtensionApplication(typeof(CreateBox.box3dcreator))]

namespace CreateBox
{
public class box3dcreator:IExtensionApplication
{
[CommandMethod("boxtest")]
public void boxc()
{
Database dbs = HostApplicationServices.WorkingDatabase;
Transaction trans = dbs.TransactionManager.StartTransaction();

ObjectId modsps = dbs.CurrentSpaceId;
BlockTableRecord blkrec = trans.GetObject(modsps, OpenMode.ForWrite) as BlockTableRecord;
Point3d cpnt = new Point3d(05, 12.50, 2.50);
Solid3d boxx = new Solid3d();
boxx.CreateBox(10, 25, 5);// how to assigning centroid ?
blkrec.AppendEntity(boxx);
trans.AddNewlyCreatedDBObject(boxx, true);

trans.Commit();
}

void IExtensionApplication.Initialize()
{
}
void IExtensionApplication.Terminate()
{
}
}
}
0 Likes
Accepted solutions (1)
429 Views
2 Replies
Replies (2)
Message 2 of 3

_gile
Consultant
Consultant
Accepted solution

Hi,

"Change the centroid" means move the box. This can be done using the Entity.TransformBy method.

boxx.TranformBy(Matrix3d.Displacement(new Vector3d(5.0, 12.5, 2.5)));


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 3

almutaz_86
Advocate
Advocate

Thank you @_gile  
its worked perfectly.

 

 

0 Likes