Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

How to see if a Point Label has been moved to Dragged State

tcorey
Mentor

How to see if a Point Label has been moved to Dragged State

tcorey
Mentor
Mentor

Hello. Here's a rooking LISP question.

 

I can access a COGO Point with Visual LISP. It shows the label style, but there doesn't appear to be a way to evaluate the label. If the label is in dragged state, I want to be able to record the label location, hoping that, once written out to csv, I can import to another drawing, with edits intact.



Tim Corey
MicroCAD Training and Consulting, Inc.
Redding, CA
Autodesk Gold Reseller

New knowledge is the most valuable commodity on earth. -- Kurt Vonnegut
0 Likes
Reply
Accepted solutions (3)
1,114 Views
6 Replies
Replies (6)

Jeff_M
Consultant
Consultant
Accepted solution
You can do this using the .NET API but not COM.
Jeff_M, also a frequent Swamper
EESignature
0 Likes

tcorey
Mentor
Mentor

Thanks, Jeff. I had a hunch this might be the case. Bummer.



Tim Corey
MicroCAD Training and Consulting, Inc.
Redding, CA
Autodesk Gold Reseller

New knowledge is the most valuable commodity on earth. -- Kurt Vonnegut
0 Likes

Jeff_M
Consultant
Consultant
Accepted solution

@tcorey Tim, I've been messing around with this and have this working:

;;Select a Point
(setq pt (car (entsel "Select point:")))
;;Check if it is dragged
(setq test (islabeldragged pt))
;;get the label location
(setq loc (pointlabellocation pt))
;;set a new label location, returns T if successful
(setq moved (pointlabellocation pt '(4332.33 3941.84 648.374)))

 

The results running in the VLIDE:

_$ (setq pt (car (entsel "Select point:")))
<Entity name: 2e6775cf890>
_$ (setq test (islabeldragged pt))
T

_$ (setq loc (pointlabellocation pt))
(4288.39 3899.92 648.374)

_$ (setq moved (pointlabellocation pt '(4332.33 3941.84 648.374)))
T

 

I will be cleaning up the code and compiling it to post soon.

Jeff_M, also a frequent Swamper
EESignature
0 Likes

Jeff_M
Consultant
Consultant
Accepted solution

Attached is a ZIP with the compiled assembly. Be sure to Unblock the ZIP after downloading, extract the DLL file to a location you can later find it. Netload it into C3D, then the 2 lisp functions will be available.

(IsLabelDragged ent) 

(PointLabelLocation ent)

(PointLabelLocation ent pt3d)

where ent must be the ENAME of a CogoPoint and pt3d must be a list of 3 doubles:  (x y z)

 

Here's the code for anyone that would like to see it:

using System;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.Civil.DatabaseServices;

namespace C3DLispTools
{
    public class CogoPointFunctions
    {
        [LispFunction("IsLabelDragged")]
        public object IsLabelDragged(ResultBuffer rbfArgs)
        {
            try
            {
                Database db = Application.DocumentManager.MdiActiveDocument.Database;
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    var arInputArgs = rbfArgs.AsArray();
                    TypedValue tv = (TypedValue)arInputArgs.GetValue(0);
                    ObjectId objId = (ObjectId)tv.Value;

                    CogoPoint pt = objId.GetObject(OpenMode.ForRead) as CogoPoint;
                    if (pt == null)
                        return "Error: Not a CogoPoint!";

                    return pt.IsLabelDragged;
                }
            }
            catch
            {
                return LispDataType.Nil;

            }
        }

        [LispFunction("PointLabelLocation")]
        public object PointLabelLocation(ResultBuffer rbfArgs)
        {
            object retval = null;
            Database db = Application.DocumentManager.MdiActiveDocument.Database;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                var arInputArgs = rbfArgs.AsArray();
                TypedValue tv = (TypedValue)arInputArgs.GetValue(0);
                ObjectId objId = (ObjectId)tv.Value;

                CogoPoint pt = objId.GetObject(OpenMode.ForRead) as CogoPoint;
                if (pt == null)
                    retval = "Error: Not a CogoPoint!";
                else if (arInputArgs.Length == 1)
                    retval = pt.LabelLocation;
                else
                {
                    try
                    {
                        pt.UpgradeOpen();
                        tv = (TypedValue)arInputArgs.GetValue(1);
                        var ptlocation = (Point3d)tv.Value;
                        pt.ResetLabelLocation();
                        pt.LabelLocation = ptlocation;
                        pt.DowngradeOpen();
                        retval = true;
                    }
                    catch
                    {
                        retval = false;
                    }
                }
                tr.Commit();
                db.TransactionManager.QueueForGraphicsFlush();
            }
            return retval;
        }
    }
}

 

Jeff_M, also a frequent Swamper
EESignature

tcorey
Mentor
Mentor

Hi @Jeff_M Thanks to your dll, I was able to create a lisp that exports points to a text file. There is a column that tells if the point label has been dragged and, if it has, then columns for label location x, y, and z. Now I intend to write a lisp that imports the points and applies the dragged location. Fun stuff!

 

 



Tim Corey
MicroCAD Training and Consulting, Inc.
Redding, CA
Autodesk Gold Reseller

New knowledge is the most valuable commodity on earth. -- Kurt Vonnegut
0 Likes

tcorey
Mentor
Mentor

Here is the LISP:

 

(defun c:DES_PtExpWithdragLoc ( / )
(vl-load-com)
(getdoc)

(vl-cmdf "netload" "C:\\Data\\_Autodesk Custom\\C3DLispTools.dll");load the dll that Jeff Mishler wrote. Thanks, Jeff!
(setq fl (open (strcat (filenamegetter) "_withDragStateLocation.txt") "w"))
(write-line "PtNumber, Easting, Northing, Elevation, Raw Description, IsDragged, Dragx, Draxy, Dragz" fl)
(setq pts (vlax-get c3ddoc 'Points)
	  cnt (vlax-get pts 'Count)
	  ctr 0)
	  
	  (while (< ctr cnt)
		(setq pt (vlax-invoke pts 'Item ctr)
			  pte (vlax-vla-object->ename pt)
			  East (vlax-get pt 'Easting)
			  North (vlax-get pt 'Northing)
			  Elev (vlax-get pt 'Elevation)
			  RawDs (vlax-get pt 'RawDescription)
			  Num (vlax-get pt 'Number)
			  )
			  
			  (if (islabeldragged pte)
					(progn
						(setq LblLoc (pointlabellocation pte)
							  lblX (car lblloc)
							  lblY (cadr lblloc)
							  lblZ (caddr lblloc)
							  )
					(setq Dragged 1)
					)
					(setq Dragged 0)
					)
					(if (= dragged 1)
						(write-line (strcat (rtos num 2 0) "," (rtos east 2 4) "," (rtos north 2 4) "," (rtos Elev 2 3) "," RawDs "," (itoa dragged) "," (rtos lblx 2 4) ","
											(rtos lbly 2 4) "," (rtos lblz 2 4))
									fl)
						(write-line (strcat (rtos num 2 0) "," (rtos east 2 4) "," (rtos north 2 4) "," 
											(rtos Elev 2 3) "," RawDs "," (itoa dragged))
									fl)
					)
			
			(setq ctr (1+ ctr))
			)
			(close fl)
			(princ)
			)


(defun filenamegetter ( / pref)
  (setq pref (getvar "DWGPREFIX")
	dwgnm (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4))
	)
  (setq dwgnm (strcat pref dwgnm))
  )




;thanks to Jeff Mishler for the following code.  
(defun getAecAppNumber (/ );c3dnumber c3dproduct c3drelease)
  (setq	C3Dproduct (strcat "HKEY_LOCAL_MACHINE\\"
			   (if vlax-user-product-key
			     (vlax-user-product-key)
			     (vlax-product-key)
			   )
		   )
	C3Drelease (vl-registry-read C3Dproduct "Release")
	C3Dnumber  (substr
		     C3Drelease
		     1
		     (vl-string-search
		       "."
		       C3Drelease
		       (+ (vl-string-search "." C3Drelease) 1)
		     )
		   )
  )
)

(defun getdoc ( / )

  (setq appno (getaecappnumber))

  (setq	acadapp	(vlax-get-acad-object)
	c3dapp	(vla-getinterfaceobject acadapp (strcat "AeccXUiLand.AeccApplication." appno))
	C3Ddoc	(vla-get-activedocument C3Dapp)
  )

)					;end function


Tim Corey
MicroCAD Training and Consulting, Inc.
Redding, CA
Autodesk Gold Reseller

New knowledge is the most valuable commodity on earth. -- Kurt Vonnegut