All Activity
- Today
-
lrm started following Geometric center of open polyline, line
-
Geometric center of open polyline, line
lrm replied to maahee's topic in AutoLISP, Visual LISP & DCL
The geometric center (a.k.a. centroid) of an open polyline is deteremined by summing the length of each line segment times the coordinates of the midpoint of the respective segment. The result is then divided by the total length of the polyline. It is NOT the average of the point locations. ; Calculates the centroid for an open lwpolyline ; lrm 8/9/2025 (defun c:pl_centroid (/ ss pt_lst sum_x sum_y sum_d n i d mid_pt centroid) (setq ss (entget (car (Entsel "\nSelect Open Polyline"))) pt_lst (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) ss) ) ) (setq sum_x 0 sum_y 0 sum_d 0.0 n (length pt_lst) i 0 ) (while (<= i (- n 2)) (setq d (distance (nth i pt_lst) (nth (+ i 1) pt_lst))) (setq mid_pt (mapcar '/ (mapcar '+ (nth i pt_lst) (nth (+ i 1) pt_lst)) '(2 2 2) ) ) (setq sum_x (+ sum_x (* (car mid_pt) d)) sum_y (+ sum_y (* (cadr mid_pt) d)) sum_d (+ d sum_d) i (+ i 1) ) ) (setq centroid (list (/ sum_x sum_d) (/ sum_y sum_d) ) ) (princ "\n Centroid at: ") (princ centroid) (command "_point" "_non" centroid) (princ) ) -
SELECT TEXTS OTHER THAN 3.5..HELP
Steven P replied to leonucadomi's topic in AutoLISP, Visual LISP & DCL
To enter the value into your selection set see below. In LISP the '( ... ) lists mean it is a static list, it is read exactly as it is written, (list ... ) means that CAD will create the list if for example variables are a part of the list, and (cons ... ), also used to create a list - in this case relevant to create a dotted pair. (setq MyThing 5) '(1 2 3 4 MyThing) is read as 1 2 3 4 MyThing - and an error since it is looking for MyThing to be a string, "MyThing" (list 1 2 3 4 MyThing) is read as 1 2 3 4 5 - list has been created by the LISP (cons 1 MyThing) is read as (1 . 5) So this might help... As above though you select the text with the selection set ss, but haven't done anything with it - if you are a part way through the LISP that is all good, but just put a report in so you can see it is working as it should as you go along perhaps (sslength SS) maybe. (Oh, just me, I also amended the indents, and added where commands end if over a few lines, I find it easier to read LISPs as below, that's all) (defun c:test (/ old_err EscVP StrScale2 TxtHt StrScale ss) (setq old_err *error*) (defun *error* ( a / ) ;; Add here return cmdecho to as it was, cmdecho 1 (princ "") (setq *error* old_err) (princ) ) ; End Error Defun (setvar "cmdecho" 0) ; perhaps record the state of cmdecho before here, and reset to that value at the end (if (and (setq EntVP (car (entsel "\Seleccione VIEWPORT: "))) (= (cdr (assoc 0 (entget EntVP))) "VIEWPORT") ) ; end and (progn (setq EscVP (vla-get-CustomScale (vlax-ename->vla-object EntVP))) (setq StrScale2 (rtos (* 3.5 (/ 1 EscVP)) 2 1)) (setq TxtHt (* 3.5 (/ 1 EscVP)) ) ; a number not a string ;; added this (setq StrScale (rtos (/ 1 EscVP) 2 2)) (setq vpnum (cdr (assoc 69 (entget EntVP )))) (vl-cmdf "_.mspace") (setvar "CVPORT" vpnum) (setq ss (ssget (list(0 . "TEXT") (-4 . "<>") (cons 40 TxtHt))) ) ;;What are you doing with ss now? (Prompt (strcat "\nLa escala de La Ventana es 1/" StrScale)) (princ "\nLos textos de 3.5 en el interior de la ventana deben ser de: ") (princ StrScale2) ) ; end progn ) ; end if (setvar "cmdecho" 1) (princ) );fin defun -
SELECT TEXTS OTHER THAN 3.5..HELP
GLAVCVS replied to leonucadomi's topic in AutoLISP, Visual LISP & DCL
Hi I think it would be easier to find the problem if you attached an example drawing. - Yesterday
-
If your making layouts then do that then go into mspace pick the page details than pop back to pspace and fill in your title block not that hard. Yes a lisp. One of the things I have looked at is pick a point on dwg in Model space, select scale, select title block and make the layout. You could add pick the mtext for title block also. It will cost you a cup of coffee as have to hard code the title block details etc.
-
Geometric center of open polyline, line
BIGAL replied to maahee's topic in AutoLISP, Visual LISP & DCL
Not quite the middle of say 2 points. The red is the average answer. The green is gcen. so 4 answers. If the shape is say 4 points then you could force a close get the Gcen then do a undo. -
SELECT TEXTS OTHER THAN 3.5..HELP
leonucadomi replied to leonucadomi's topic in AutoLISP, Visual LISP & DCL
thanks, now I explain In the modelspace I have texts of different height in paperspace in the paperspace I have viewports of different scales If I use the chspace command and take those texts to paper space they should be 3.5 height I'm looking for a routine that helps me detect which texts do not meet that height in each viewport (defun c:test (/ EscVP StrScale2 StrScale) (setq old_err *error*)(defun *error* ( a / )(princ "") (setq *error* old_err)(princ)) (setvar "cmdecho" 0) (if (and (setq EntVP (car (entsel "\Seleccione VIEWPORT: "))) (= (cdr (assoc 0 (entget EntVP))) "VIEWPORT")) (progn (setq EscVP (vla-get-CustomScale (vlax-ename->vla-object EntVP))) (setq StrScale2 (rtos (* 3.5 (/ 1 EscVP)) 2 1)) (setq StrScale (rtos (/ 1 EscVP) 2 2) ) (setq vpnum (cdr (assoc 69 (entget EntVP ) ) ) ) (vl-cmdf "_.mspace") (setvar "CVPORT" vpnum) (setq ss (ssget '((0 . "TEXT") (-4 . "<>") (40 . 3.5))) ) (Prompt (strcat "\nLa escala de La Ventana es 1/" StrScale)) (princ "\nLos textos de 3.5 en el interior de la ventana deben ser de: ") (princ StrScale2) ) ) (setvar "cmdecho" 1) (princ) );fin defun I am looking to enter this calculated value here but it doesn't work -
Steven P started following SELECT TEXTS OTHER THAN 3.5..HELP
-
SELECT TEXTS OTHER THAN 3.5..HELP
Steven P replied to leonucadomi's topic in AutoLISP, Visual LISP & DCL
This (ssget '((0 . "TEXT") (-4 . "<>") (40 . 3.5))) should work. You can change "TEXT" to "*TEXT" to also capture MText Though looking at the code you have, I am assuming that is just a snippet of what you want to do. Here are a couple of hints: (defun c:pru ( / ss ) ;;Yup localised variables, C: prompt, all good (setq ss (ssget '((0 . "TEXT") (-4 . "<>") (40 . 3.5))) ) ;; ADDED (SETQ SS ... ) so that you can use the selection set later (princ (sslength ss)) ;; Added this in to show the result of the selection set (princ) ;;Exit quietly ) -
SELECT TEXTS OTHER THAN 3.5..HELP
leonucadomi replied to leonucadomi's topic in AutoLISP, Visual LISP & DCL
(defun c:pru2 ( / ss alturaColor colorNuevo) (setq alturaColor 3.5) ; Define la altura a verificar (setq colorNuevo 1) ; Define el color a aplicar (ej. rojo) (setq ss (ssget "X" '((0 . "TEXT,MTEXT")))) ; Selecciona todos los textos (if ss (progn (setq i 0) (while (setq en (ssname ss i)) (setq obj (vlax-ename->vla-object en)) (if (/= (vla-get-height obj) alturaColor) (vlax-put-property obj 'color colorNuevo) ; Cambia el color ) (setq i (1+ i)) ) ) ) (princ) ) This routine does what I need, but it has a problem that I cannot understand, I have objects in the paperspace that have a height of 3.5 and it recognizes them as if they did not have it and changes them to red. can someone help? thanks -
Dadgad started following SNAP mode hints
-
SNAP mode hints
Dadgad replied to Discus84's topic in AutoCAD 2D Drafting, Object Properties & Interface
LI & LU Layer isolate and Layer unisolate are extremely helpful, I concur. I also favor "all off" rather than "Fade". I am quite partial to the LAYERS 2 toolbar also. -
@SLW210 Thanks. I will take a look at that. @BIGAL Thanks for the code. We stopped using sheet titles on our titleblocks. Sometimes we would end up having too many drawings on a single page and there wouldnt be enough room for it all on titleblock. We removed it and opted for a Table of Contents with all the labels. And yes we do primarily work in modelspace but all our current titleblocks are located in Paperspace. The drawing titles are located below the drawings in model space. Our table of contents is in modelspace as well. Our model space typically looks like this. Where as our Titleblock version of that looks like this ( the red blob is our company info blanked out)... The fields in the titleblock are linked to dwgprops for easy updating. Page # on the bottom right is a diesel expression that pulls the layout name. Anyways, the only method I can think about doing this is to select each drawing title in model space and have the lisp auto number the pages and organize in a table or formatted MTEXT.
-
SELECT TEXTS OTHER THAN 3.5..HELP
leonucadomi replied to leonucadomi's topic in AutoLISP, Visual LISP & DCL
I ALREADY TRIED IT AND IT SELECTED THEM ALL FOR ME, I DON'T KNOW WHAT HAPPENS My purpose is to detect all texts that do not have a desired height, in this case 3.5 -
Hi, I use ZWCAD and the Express is loaded I try what GP_ and enthralled said to solve the problem but get this error Command: CPL Error: ZWCAD setvar reject: LOFTNORMALS 0 Any ideas? Thanks
-
At home I have some file compare programs, Notepad++ with the Compare plug-in as well. IIRC, there are some online as well, WinMerge I think is one of my programs, I use AntiTwin to find duplicate files, it may have a compare function. So while everyone is doing there jobs, if YOU have the time, you might could compare the file and see what all is different. At least that will be a start, maybe I can talk IT into putting one of those programs on my work computer. I used to have a program from CabloFil, not sure if they still have anything for doing cable trays in AutoCAD. Here it is... Cable Management 3D Modeling Tools | Legrand I haven't done a cable tray in ages, so not sure what all it does.
-
Saxlle started following Geometric center of open polyline, line
-
Geometric center of open polyline, line
Saxlle replied to maahee's topic in AutoLISP, Visual LISP & DCL
You can actually calculate it, here is the code (you can change it for your purposes): (setq ptlist (mapcar 'cdr (vl-remove-if-not (function (lambda (x) (= (car x) 10))) (setq ent (entget (car (entsel "\nSelect the line:")))))) ;; point list sum_x 0 sum_y 0 vertices (cdr (assoc 90 ent)) ;; number of vertices for LWPOLYLINE ) (foreach pt ptlist (setq sum_x (+ sum_x (car pt))) ;; sum only the X vertices values ) (foreach pt ptlist (setq sum_y (+ sum_y (cadr pt))) ;; sum only the Y vertices values ) (setq sum_x (/ sum_x vertices) ;; dividing the total sum X by the number of vertices sum_y (/ sum_y vertices) ;; dividing the total sum Y by the number of vertices pt (list sum_x sum_y) ;; geometric center ) Below are the pictures with geometric center for open and closed polyline (picture 1 open, picture 2 closed). Picture 1. Picture 2. This is true. Best regards. -
Geometric center of open polyline, line
DATVO replied to maahee's topic in AutoLISP, Visual LISP & DCL
Only the geometric center is available for closed areas, since open polylines have no area and therefore no true center. If it’s just a line, the "geometric center” is the midpoint. -
Generally were busy people this week - if you open the LISP in a text editor, search for the line that asks for the new width - problem will be sometime after that - but will narrow down the issue a bit and give a less daunting task
-
(setq gct (osnap (vlax-curve-getStartPoint bm) "gcen")) The above code line gives only closed polyline How to find the geometric center of an open polyline and a single line
-
SELECT TEXTS OTHER THAN 3.5..HELP
DATVO replied to leonucadomi's topic in AutoLISP, Visual LISP & DCL
Try this: ;; Modified by DV. Visit my page at: https://lispautocad.gumroad.com/ (defun c:PRU (/ ss) (if (setq ss (ssget '((0 . "TEXT,MTEXT") (-4 . "<>") (40 . 3.5)))) (progn (sssetfirst nil ss) (princ (strcat "\nSelecting: " (itoa (sslength ss)) " objects.")) ) (princ "\nNo Object.") ) (princ) ) -
Like the others 800 lines of code, I struggle remembering what I wrote around that number of lines from a year or two ago. Having to work out why program not working with some new dwg's 678 lines of code at the moment. I had to write an error trap to just find where it was failing. You have been offered other solutions, the Tharwat solution would be my pick and he is a regular here so you could contact him if you had questions or want more.
-
For me I use layouts and a Title block then can make an index of all layouts. Here is a copy of the code have a look at it. It looks from image that your using model space and not layouts. Dwgindex.lsp
-
Here’s a tool that might help: https://lispautocad.gumroad.com/l/eezilo
- Last week
-
leonucadomi started following SELECT TEXTS OTHER THAN 3.5..HELP
-
hello guys: I need a selection filter to select texts and mtext other than 3.5 in size try this code from Master Lee (ssget '((0 . "CIRCLE") (-4 . "<>") (40 . 5.0))) modified (defun c:pru (/ ss ) (ssget '((0 . "TEXT") (-4 . "<>") (40 . 3.5))) (princ) ) I need to identify texts other than 3.5 with some color. help please thanks
-
I doubt if I'll have time this week.
-
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/automated-sheet-index-lisp-assistance/td-p/9057520
-
Strydaris started following Table of contents
-
Hi everyone, I have been looking around to see if anyone has made anything to help in the creation of a "Table of Contents". In my line of work, we need to match exactly the Drawing title to the Table of Contents reference and page number. For Example, the image below shows the ends result that I need. The image below shows what is under the drawings we produce. The title of this drawing is below in red. The above image is incorrectly labeled and should say "A4 MAIN FLOOR PLAN ELEVATION 'A' " (The 10' Ceiling part is not required generally). If there is multiple titles on a page then all of those need to be added to the ToC and might look something like this. A11 PARTIAL BASEMENT PLAN 'B' PARTIAL GROUND FLOOR PLAN 'B' PARTIAL SECOND FLOOR PLAN 'B' We currently use a formatted MTEXT to hold all this information where the A## is the page number on a new line and the contents is 2 tabs over. We use also use 2 columns for the list. So What I was thinking is having an auto numbering Page number in a lisp and then selecting the drawing titles to add next to the page number. In theory this will work but I have 2 major issues that I cant seem to get around right now. First, if the drawings titles that I select is an mtext with formatting, I cant find a way around removing the formatting. I am using ACAD 2024 LT and Lee Mac's "LM:Unformat string" doesnt work, neither does StripMtext. Does anyone have an idea to get around this? Secondly, I do not know how to build an mtext to include new formatting. Like how do you make sure you start a new line or add tabs before the next piece of text is added to the mtext? I am even up for other suggestions on how to create a Table of Contents.... except I cant use Sheet Sets. Our office doesn't want move in that direction just yet. Thanks.