Jump to content

Recommended Posts

Posted

Does anyone knows if it is possible to use a variable instead of explicitly enter the code name?, I tried but got an error, 

Posted
4 hours ago, morgos said:

Does anyone knows if it is possible to use a variable instead of explicitly enter the code name?, I tried but got an error, 

 

Your explanation is too short for some like me.
If you continue to seek help, you should elaborate a bit more on the explanation.

Posted

Can you post an example of what you are trying to do.... though I think Lee Mac has it covered - that's the common mistake

Posted (edited)

I am trying to trim contours inside buildings, my lisp iterates through the buildings in the dwg one by one and the user clicks on the contours inside the building to trim it, it works fine but I wanted to make it more general and the user enters the layer name which he\she wants the contours to be trimmed, 

here is my code so far:

(defun C:MySel ( / sel1 n PArea Bname)
    (terpri)
    (princ "Enter Layer Name: ")
    (setq LayName (getstring))
            (princ "\n")
            (princ LayName)
    (setq sel1 (ssget "_X" '((0 . "*POLYLINE")(8 . "Buildings"))));layer Name does not accept variables
    (repeat(setq n (sslength sel1))
        (setq Bname (cdr(assoc -1 (entget (ssname sel1 (setq n (- n 1)))))));;;get the entity name
        (command "._z" "_en" Bname "")
            (princ "\n")
            (princ n)

        (command "._TR" Bname "" pause )

    )
        (princ)
)

 

when I changed "Buildings" into LayName I got the error ( error: bad SSGET list), Lee Mac may got that covered, I will work on that tonight and let you know if any success, 

Edited by morgos
Posted
17 minutes ago, morgos said:

when I changed "Buildings" into LayName I got the error ( error: bad SSGET list), Lee Mac may got that covered, I will work on that tonight and let you know if any success, 

 

See if you can work it out from my tutorial and come back if you require further nudges ;)

Posted (edited)

thanks Lee, your tutorial is awesome, it looks that you wrote it just for me 😉 , here is my final Lisp:

 

(defun C:MySel ( / sel1 n LayName Bname)
    (terpri)
    (if (snvalid (setq LayName (getstring t "\nSpecify layer: ")))
        (setq sel1 (ssget "_X" (list '(0 . "POLYLINE")(cons 8 LayName))))
    )
    (princ "\nOK")
    (princ (sslength sel1))
    
    (repeat(setq n (sslength sel1))
        (setq Bname (cdr(assoc -1 (entget (ssname sel1 (setq n (- n 1)))))));;;get the entity name
        (command "._z" "_en" Bname "")
            (princ "\n")
            (princ n)
        (command "._TR" Bname "" pause )
    )
        (princ)
)

 

 

in a different issue, when I ( the user) clicks on the contour, the contours trims fine once then the building no longer selected, so if there are more than one contour inside the building the rest of them cannot be trimmed unless you run the lisp again until all the contours are trimmed, any idea how to keep the building selected until the user hits enter?

Edited by morgos
Posted

You're most welcome :)

 

To continue the TRIM command, you can use something like:

(command "_.trim" bname "")
(while (= 1 (logand 1 (getvar 'cmdactive))) 
    (command "\\")
)

 

Note that the pause symbol evaluates to a backslash - I prefer to use the literal backslash as pause is not protected and has the potential to be redefined.

Posted

I normally use this for get layer name.

(setq layname (cdr (assoc 8 (entget (car (entsel "\nPlease select object for layer "))))))

I would look at using "fence" in the trim can select multiple crossing lines.

image.png.247ec55d08b127a3a99f57e787d34fc1.png

Posted
10 hours ago, morgos said:

        (setq Bname (cdr(assoc -1 (entget (ssname sel1 (setq n (- n 1)))))));;;get the entity name

 

Note that the above is the same as:

(setq bname (ssname sel1 (setq n (- n 1))))

 

Posted
12 hours ago, Lee Mac said:

You're most welcome :)

 

To continue the TRIM command, you can use something like:

(command "_.trim" bname "")
(while (= 1 (logand 1 (getvar 'cmdactive))) 
    (command "\\")
)

 

Note that the pause symbol evaluates to a backslash - I prefer to use the literal backslash as pause is not protected and has the potential to be redefined.

Lee: this is working exactly as mine, the trim command stays active, but my issue is the building ( the cutting edge ) is not selected any more after one click 

Posted

hi Lee, sorry, discard my last comment, my bad, i loaded the wrong Lisp file, your last snippet worked exactly the way i wanted,  problem solved, thanks for all your help

 

 

Posted

Bigal:

I normally use this for get layer name.

(setq layname (cdr (assoc 8 (entget (car (entsel "\nPlease select object for layer "))))))

 

i like that, picking from the screen instead of typing the layer name,  thanks.

 

Posted
5 hours ago, Lee Mac said:

 

Note that the above is the same as:

(setq bname (ssname sel1 (setq n (- n 1))))

 

oh, nice ...

Posted

now it is working exactly the way i wanted, thanks everybody, you were wonderful, here is my final Lisp if anyone find it useful. please note that i am just a hobbyist,   my code is fast and dirty, no error trapping: 

 

(defun C:MySel ( / sel1 n LayName Bname)
    (terpri)
    (setq LayName (cdr (assoc 8 (entget (car (entsel "\nPlease select object for layer "))))))
        (setq sel1 (ssget "_X" (list '(0 . "POLYLINE")(cons 8 LayName))))
    (princ "\nOK")
    (princ (sslength sel1))
    
    (repeat(setq n (sslength sel1))
        (setq Bname (ssname sel1 (setq n (- n 1))))
        (command "._z" "_en" Bname "")
            (princ "\n")
            (princ n)
        (command "._TR" Bname "")
        (while (= 1 (logand 1 (getvar 'cmdactive))) 
            (command "\\")
        )
    )

 

Posted
1 hour ago, morgos said:

now it is working exactly the way i wanted, thanks everybody, you were wonderful, here is my final Lisp if anyone find it useful. please note that i am just a hobbyist,   my code is fast and dirty, no error trapping: 

 

(defun C:MySel ( / sel1 n LayName Bname)
    (terpri)
    (setq LayName (cdr (assoc 8 (entget (car (entsel "\nPlease select object for layer "))))))
        (setq sel1 (ssget "_X" (list '(0 . "POLYLINE")(cons 8 LayName))))
    (princ "\nOK")
    (princ (sslength sel1))
    
    (repeat(setq n (sslength sel1))
        (setq Bname (ssname sel1 (setq n (- n 1))))
        (command "._z" "_en" Bname "")
            (princ "\n")
            (princ n)
        (command "._TR" Bname "")
        (while (= 1 (logand 1 (getvar 'cmdactive))) 
            (command "\\")
        )
    )

 

You have a missing parenthesis in that snippet. Here's some simple refactoring for better error handling:
 

(defun c:mysel (/ sel1 n layname bname)
  ;; Check that the selection is valid before using ENTGET
  (if (and (setq layname (car (entsel "\nPlease select object for layer ")))
	   (setq layname (cdr (assoc 8 (entget layname))))
	   (setq sel1 (ssget "_X" (list '(0 . "POLYLINE") (cons 8 layname))))
      )
    (repeat (setq n (sslength sel1))
      (setq bname (ssname sel1 (setq n (- n 1))))
      (command "._z" "_en" bname "")
      (princ "\n")
      (princ n)
      (command "._TR" bname "")
      (while (= 1 (logand 1 (getvar 'cmdactive))) (command "\\"))
    )
  )
  ;; Exit quietly
  (princ)
)

 

Posted
6 hours ago, ronjonp said:

You have a missing parenthesis in that snippet. Here's some simple refactoring for better error handling:
 

(defun c:mysel (/ sel1 n layname bname)
  ;; Check that the selection is valid before using ENTGET
  (if (and (setq layname (car (entsel "\nPlease select object for layer ")))
	   (setq layname (cdr (assoc 8 (entget layname))))
	   (setq sel1 (ssget "_X" (list '(0 . "POLYLINE") (cons 8 layname))))
      )
    (repeat (setq n (sslength sel1))
      (setq bname (ssname sel1 (setq n (- n 1))))
      (command "._z" "_en" bname "")
      (princ "\n")
      (princ n)
      (command "._TR" bname "")
      (while (= 1 (logand 1 (getvar 'cmdactive))) (command "\\"))
    )
  )
  ;; Exit quietly
  (princ)
)

 

Thanks

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...