creating ordinate dimensions

creating ordinate dimensions

BKSpurgeon
Collaborator Collaborator
826 Views
3 Replies
Message 1 of 4

creating ordinate dimensions

BKSpurgeon
Collaborator
Collaborator

Hi folks

 

I'm having a little trouble creating an ordinate dimension.

 

I want the ordinate dimension to be on the UCS not the WCS.

 

Here is my code:

 

 [CommandMethod("CreateOrdinateDimension")]
        public static void CreateOrdinateDimension()
        {
            // Get the current database
            Document acDoc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = acDoc.Editor;
            Database acCurDb = acDoc.Database;

            // Start a transaction
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // Open the Block table for read
                BlockTable acBlkTbl;
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                                OpenMode.ForRead) as BlockTable;

                // Open the Block table record Model space for write
                BlockTableRecord acBlkTblRec;
                acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                                OpenMode.ForWrite) as BlockTableRecord;

                // Create an ordinate dimension
                using (OrdinateDimension acOrdDim = new OrdinateDimension())
                {
                    acOrdDim.UsingXAxis = true;

                    //// this seems to print the dimension at the WCS origin?
                    //acOrdDim.DefiningPoint = new Point3d(0,0,0);
                    //acOrdDim.LeaderEndPoint = new Point3d(0, 0, 0);

                    ////this seems to print at the UCS origin, but the numbers used are in fact WCS?
                    acOrdDim.DefiningPoint = new Point3d(0, 0, 0).TransformBy(ed.CurrentUserCoordinateSystem);
                    acOrdDim.LeaderEndPoint = new Point3d(0, 0, 0).TransformBy(ed.CurrentUserCoordinateSystem);

                    acOrdDim.DimensionStyle = acCurDb.Dimstyle;

                    // Add the new object to Model space and the transaction
                    acBlkTblRec.AppendEntity(acOrdDim);
                    acTrans.AddNewlyCreatedDBObject(acOrdDim, true);
                }

                // Commit the changes and dispose of the transaction
                acTrans.Commit();
            }
        }

 

Attached is my drawing file.

  • The circle centre marks the WCS origin.

 

The problem

  • when i transform the defining and leader points by UCS, it does print to the UCS origin, but it is not saying 0. It is giving me the WCS numbers.
  • When I do not transform by UCS, the correct numbers are shown, but it displays it at the WCS origin, not the UCS origin.

 

I want it to print at the UCS origin, and have it also display 0 at the same time.

 

assistance much appreciated.

 

chrs

 

 

0 Likes
Accepted solutions (1)
827 Views
3 Replies
Replies (3)
Message 2 of 4

deepak.a.s.nadig
Alumni
Alumni

Can you please try to set identity matrix to the current UCS before defining the ordinate DefiningPoint and LeaderEndPoint in  your code ? 

            ed.CurrentUserCoordinateSystem = Matrix3d.Identity 

Here is the modified code: 

[CommandMethod("CreateOrdinateDimension")]
		public static void CreateOrdinateDimension()
		{
			// Get the current database
			Document acDoc = Application.DocumentManager.MdiActiveDocument;
			Editor ed = acDoc.Editor;
			Database acCurDb = acDoc.Database;

			// Start a transaction
			using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
			{
				// Open the Block table for read
				BlockTable acBlkTbl;
				acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
												OpenMode.ForRead) as BlockTable;

				// Open the Block table record Model space for write
				BlockTableRecord acBlkTblRec;
				acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
												OpenMode.ForWrite) as BlockTableRecord;

				// Create an ordinate dimension
				using (OrdinateDimension acOrdDim = new OrdinateDimension())
				{
					acOrdDim.UsingXAxis = true;

					ed.CurrentUserCoordinateSystem = Matrix3d.Identity;

					//// this seems to print the dimension at the WCS origin?
					acOrdDim.DefiningPoint = new Point3d(0, 0, 0);
					acOrdDim.LeaderEndPoint = new Point3d(0, 0, 0);

					////this seems to print at the UCS origin, but the numbers used are in fact WCS?
					//acOrdDim.DefiningPoint = new Point3d(0, 0, 0).TransformBy(ed.CurrentUserCoordinateSystem);
					//acOrdDim.LeaderEndPoint = new Point3d(0, 0, 0).TransformBy(ed.CurrentUserCoordinateSystem);

					acOrdDim.DimensionStyle = acCurDb.Dimstyle;


					// Add the new object to Model space and the transaction
					acBlkTblRec.AppendEntity(acOrdDim);
					acTrans.AddNewlyCreatedDBObject(acOrdDim, true);
				}

				// Commit the changes and dispose of the transaction
				acTrans.Commit();
			}
		}

 

0 Likes
Message 3 of 4

BKSpurgeon
Collaborator
Collaborator

Hello thank you

 

The solution did not work for me.

 

I will present the problem and the solution which did work as soon as able.

 

with kind regards

 

BK

0 Likes
Message 4 of 4

_gile
Consultant
Consultant
Accepted solution

Hi,

 

If you want the dimension to be related to current UCS coordinates, you have to tranform the defining and leader end points to UCS coordinates.

If you want the ordinate dimension origin to be the same as the UCS origin you have to set the OrdinateDimension.Origin property.

 

        public void CreateOrdinateDimension()
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            var ptRes = ed.GetPoint("\nSpecify feature location: ");
            if (ptRes.Status != PromptStatus.OK)
                return;
            var pt = ptRes.Value.TransformBy(ed.CurrentUserCoordinateSystem);

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                var ms = (BlockTableRecord)tr.GetObject(
                    SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForWrite);
                
                using (OrdinateDimension dim = new OrdinateDimension())
                {
                    dim.UsingXAxis = true;
                    dim.DefiningPoint = pt;
                    dim.LeaderEndPoint = pt;
                    dim.Origin = Point3d.Origin.TransformBy(ed.CurrentUserCoordinateSystem);

                    dim.DimensionStyle = db.Dimstyle;

                    ms.AppendEntity(dim);
                    tr.AddNewlyCreatedDBObject(dim, true);
                }
                    tr.Commit();
            }
        }

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub