Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Old lisp routine to find centroid of selected points no longer can be used as a transparent command

18 REPLIES 18
SOLVED
Reply
Message 1 of 19
JoeHoffmayer
1182 Views, 18 Replies

Old lisp routine to find centroid of selected points no longer can be used as a transparent command

Hi All,

I have a simple routine that used to work as a transparent command.  It finds the centroid of a bunch of selected points.  I used to be able to transparently use this during the line command.  While in the line command, I could select other snap points around the drawing and the program would find the point at the centroid of my selection and continue the line command to that point.  I could use the command at any time while drawing lines.  Now with 2022, if I start the line command and then immediately run the program, the start point of my line will be the centroid as expected.  However, if I have started to draw the line and am attempting to select the next point, the program seems turn of the cursor, turn off the rubber-band line, does not appear to snap to anything, but the coordinates in the status bar update.  When exiting out of the transparent command, the line comes back alive from some random point I can not verify...it might be the centroid of random picks on the screen, but I can't tell what I've picked.

Have any system variables changed that affect this behavior?  Or, is this method of programming just obsolete?

AutoCAD 2022 on Windows 10 Pro 64 bit.

 

;Avepnts Snap 1.0
;Use as transparent command to locate the center point between multiple picks while a
;command is active
;
;Transparent Commad 'avepnts
(defun C:AVEPNTS ()
  (pickpoints)
  (avecalc)
)
;returns the average x,y, and z ordinate values of a group of pick points
(defun AVECALC ()
        (setq x 0.0 y 0.0 z 0.0);initialize coordinate values to zero
    (foreach pt pts (setq x (+ x (car pt)))(setq y (+ y (cadr pt)))(setq z (+ z (caddr pt))))
    (setq x (/ x cnt))
    (setq y (/ y cnt))
    (setq z (/ z cnt))
    (list x y z)
)
;pickpoints input routine
(defun pickpoints (/ pt)
    (setq pts nil cnt 0)  ;clears the pts list and sets the counter to zero
        (princ "\nSelect First Point")
    (while (setq pt (getpoint "\n"))
    (setq pts (append pts (list pt)))
    (setq cnt (1+ cnt))
    (princ (strcat "\nSelect Next Point:" (itoa (+ 1 cnt))))
  )
  (princ (strcat "\nTotal Picks = " (itoa cnt)))
    (princ)
)
;returns list pts containing coordinates of picks and integer containing the number of picks

 

Labels (2)
18 REPLIES 18
Message 2 of 19
pbejse
in reply to: JoeHoffmayer

 


@JoeHoffmayer wrote:

... the line comes back alive from some random point I can not verify...it might be the centroid of random picks on the screen, but I can't tell what I've picked.


It appears to be working fine on my initail test though there could be some improvements. But so you know, To be honest i dont have an idea as far as  what "works"  really means.

 

Does it work on a lower version as expected with the same scenario or file?

 

 

 

Message 3 of 19
JoeHoffmayer
in reply to: pbejse

If you are actively in the line command and run this as a transparent command, and be able to continue selecting points on the screen in order to find the centroid for the next point of the line, then it "works" as intended.   It's an old program I quickly wrote to be able to simply put something at the imaginary center of several points.

 

When I'm running the transparent command, my screen simply stops showing me feedback of where the mouse is...I can tell the mouse has moved because the coordinates update, but there is nothing showing on the screen, and I have no control of the points I select...snap, or otherwise...so for me it does not "work".

 

Thank you for checking it out and reporting back to the forum.  If there is no obvious variable or improper use of the getpoint command, then I suspect this may be a graphics card problem on my end.

Message 4 of 19
JoeHoffmayer
in reply to: pbejse

Forgot to answer the second part...

 

Yes, this has worked on every version of Autocad I've had since 1998.

This is a new problem for me since updating to 2022.

Message 5 of 19

if the poyline already exists, then 

;;  (princ (LM_PolyCentroid (car (entsel)))

Very good solution.. you concat two function 

;;(princ (LM_PolyCentroid  (dfn_getandmake_polyline)))

(Defun c:opl (/ $rr)

 

 

 

 

(Defun dfn_getandmake_polyline( / $rr ptc idx strm pix)
  (princ "\nYou create on -polyline")
  (setq idx 0);;This solution not tested-yet. I enter from mySmarthpne with Android
  (command "_pline") 
  (setq $rr (entlast))
  (setq ptc (getpoint "\n Give me point0:")) 
  (while ptc
    (setq pix (strcat (rtos (car ptc) 2 4) "," (rtos (cadr ptc) 2 4)))
    (command pix)
    (setq idx (1+ idx))
    (setq strm (strcat "\nGive me point" (itoa idx) ":"))
    (prompt strm)
    (setq ptc (getpoint ptc))   
    (setq pix (if ptc (strcat (rtos (car ptc) 2 4) "," (rtos (cadr ptc) 2 4)) nil))
    (if pix (command pix)) 
   );;off-while
  (if (/= $rr (entlast)) (setq $rr (entlast)) (setq $rr nil))
$rr)
          

 

 

 

 

 

Message 6 of 19

Thank you for the reply and the code.  I should note that my little program is not specifically and only for drawing a line to the centroid of a group of picked points, it can really be used like an osnap when in any command that is placing an entity.  It used to work for everything;  inserting blocks, drawing lines, plines, etc.

I worked at it a bit and discovered the problem is with the getpoint command.  It simply turns off the rubber band line if I'm in a command and makes moving about the screen impossible to coordinate.  Once a point is picked from the getpoint command, the rubber band line comes back alive.

This occurs if a command is active.  If there is no command active and I run a getpoint from lisp, the cursor stays on the screen and I can use snaps to coordinate where I'm picking.

The problem appears to be somehow related to what the cursor is doing during a transparent command and my graphics card...NVIDIA GeForce MX450  27.21.14.6230  DirectX 12.

 

Are there variables to control the cursor during selection?

Message 7 of 19
john.uhden
in reply to: JoeHoffmayer

I don't know if there's some new variable that controls input during a command, but

since you are drawing only lines, your code could terminate the current line command, use your average thingy to get the next point and resume the line command by calling (getvar "lastpoint") for where you had temporarily terminated.

John F. Uhden

Message 8 of 19
ronjonp
in reply to: JoeHoffmayer

Unfortunately this is a known graphics 'feature' introduced in 2022.

Message 9 of 19
JoeHoffmayer
in reply to: john.uhden

The routine used to work for any input...so not just drawing lines.  I could be in the process of inserting blocks and choose the routine from an icon and it would go into the selection process  to find the midpoint between several snaps, then place the block at the calculated point.  It worked great.  It was actually an expansion of a MIDPOINT routine that would find the midpoint between two snaps.  I kept the midpoint routine and assigned it to an icon, then made the centroid routine by expanding the selection to as many picks as you want.   Both lisp routines worked perfectly until I got a new computer and updated to AutoCAD 2022.  Not sure it's AutoCAD, but possibly the graphics card.

I did completely change the MIDPOINT routine to use the actual built in function in AutoCAD...that works transparently.

I will take your suggestion and try to build a list, find the average x,y and z point, and set that to lastpoint.  That should work.   Need a few days to get around to it.  Thanks for the suggestion.

Message 10 of 19
JoeHoffmayer
in reply to: ronjonp

possibly a 'feature' of my graphics card also...using a laptop for CAD...not the best graphic situation

Message 11 of 19
ronjonp
in reply to: JoeHoffmayer


@JoeHoffmayer wrote:

possibly a 'feature' of my graphics card also...using a laptop for CAD...not the best graphic situation


I don't think it's your card .. I have a fairly stout Nvidia Quadro and get the same results here. ;/

Message 12 of 19
ronjonp
in reply to: JoeHoffmayer

Here's another way to get those points .. there is definitely a display bug in 2022.

 

(defun c:foo (/ _vx ap aps p)
  (defun _vx (pt clr / a vs)
    (setq a  (/ pi 4.)
	  vs (* 0.025 (getvar 'viewsize))
    )
    (repeat 4 (grdraw pt (polar pt (setq a (+ a (/ pi 2.))) vs) clr))
    (princ)
  )
  (defun _ap (pl) (mapcar (function (lambda (x) (/ x (length pl)))) (apply 'mapcar (cons '+ pl))))
  (while (setq p (getpoint "\nPick points to average: "))
    (redraw)
    (setq aps (cons p aps))
    (_vx (setq ap (_ap aps)) 3)
    (foreach x aps (grdraw ap x 8))
  )
  ap
)

2021-06-23_14-24-59.gif

 

Message 13 of 19
john.uhden
in reply to: ronjonp

@ronjonp
Very clever.
Reminds me of my LABEL_IT program where I used pseudo-glyphs and
unglyphs during a continuous (grread) to keep the glyphs drawn and sized
even while the user is transparently zooming and panning around.

John F. Uhden

Message 14 of 19
JoeHoffmayer
in reply to: ronjonp

Thank you for your code.

I tried it and still my screen drops the cursor when looking to pick points.

I tried changing DNYMODE, and no difference...so, I'm going to put this on the back burner for now and get some work done.  I will pick this up again when I get inspired.

Thank you all - appreciate all the help.

 

Message 15 of 19
Anonymous
in reply to: JoeHoffmayer

In AutoCAD 2022 (up through update 2022.1), if system variable LISPSYS is set to 0 (mode for legacy Visual LISP IDE) then display will freeze when AutoLISP function getpoint, getorient, getdist, getangle, getint or getreal are executed transparently at prompt for second point with commands such as LINE, PLINE, MOVE, COPY, ROTATE, etc.  Workaround is to set LISPSYS to 1 (mode for Visual Studio IDE) and restart AutoCAD.  Issue occurs with ActiveX methods for getting input as well, such as GetPoint.

Message 16 of 19
JoeHoffmayer
in reply to: Anonymous

Thanks for the reply.  I got excited.  I see my Lispsys is 1 - and it doesn't rubberband the cursor when picking points.

I thought to toggle the variable to 0...no change.  Back to 1...still no change.

I wish this was it.  In fact, that is what I expected it to be...some sort of variable that effects the graphics but not the function.  Keep in mind - the program does find the mid point (I actually have another version that finds the centroid of several selection picks that works too) except you can't see what you are selecting.  Which means the program does not work.   

Thanks again,

Back to the drawing board...

Message 17 of 19
Anonymous
in reply to: JoeHoffmayer

Sorry this didn't fix it. Did you restart AutoCAD after setting LISPSYS to 1? Changes to LISPSYS require restarting AutoCAD to take effect.
Message 18 of 19
JoeHoffmayer
in reply to: JoeHoffmayer

Hold on - it was set to 1 when I checked...and not working.   I've been working with LISPSYS set to 1 for who knows how long.   Based on your suggestion, I toggled it to zero and restarted autocad and it didn't work. (which we might have expected).  Then toggled it back to 1.         I didn't restart it again.

After a new restart it works!  I get the osnaps (not a rubber band) but that is just fine.  You need to see what you snap to in order to get a centroid between the picks.

IT WORKS!!!!  YES!  Thank you!

 

Best wishes - Joeh

Message 19 of 19
Anonymous
in reply to: JoeHoffmayer

I have my own custom object snaps - a custom "From" and "From Perp" - which stopped working in AutoCAD 2022 when used transparently. I have ongoing support case with Autodesk. After many hours of my own investigation, I found LISPSYS=0 to be source of the issue.
The attached is a tweaked version of your routine with "rubberband" functionality. I also did some more proper formatting - declared variables, passed arguments, etc. Hope this is closer to what you wanted.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Customer Advisory Groups


Autodesk Design & Make Report