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

adding select similar to a lisp

17 REPLIES 17
Reply
Message 1 of 18
artur_isa
2143 Views, 17 Replies

adding select similar to a lisp

hey i found this lisp and i want to change it so it will work on multiple circles (select objects inside multiple circles)

 


(defun C:ICS (/ en ss lst ssall tmp head)
;;InSide Contour Select
;;!!!! REQUIRED EXPRESS TOOLS
(vl-load-com)
(if (and (setq en (car (entsel "\nSelect contour: ")))
(wcmatch (cdr (assoc 0 (entget en))) "*POLYLINE")
) ;_ end of and
(progn
(setq lst (ACET-GEOM-OBJECT-POINT-LIST en 1e-3))
(setq lst (mapcar '(lambda (x) (list (car x) (cadr x))) lst))
(while lst
(setq head (car lst)
tmp (cons head tmp)
lst (vl-remove-if
'(lambda (pt) (equal pt head 1e-6))
(cdr lst)
) ;_ end of vl-remove-if
) ;_ end of setq
) ;_ end of while
(setq lst (reverse tmp)) ;_ end of setq
(ACET-SS-ZOOM-EXTENTS (ACET-LIST-TO-SS (list en)))
(command "_.Zoom" "0.95x")
(if (setq ss (ssget "_CP" lst))
(sssetfirst ss ss)
) ;_ end of if
) ;_ end of progn
) ;_ end of if
) ;_ end of defun
(princ "\nType ICS")

17 REPLIES 17
Message 2 of 18
taiki84
in reply to: artur_isa

hello

 

just if you want select on one circle it's simple:

(defun C:ICS (/ en ss lst ssall tmp head)
;;InSide Contour Select
;;!!!! REQUIRED EXPRESS TOOLS
(vl-load-com)
(if (and (setq en (car (entsel "\nSelect contour: ")))
;(wcmatch (cdr (assoc 0 (entget en))) "*POLYLINE")
) ;_ end of and
(progn
(setq lst (ACET-GEOM-OBJECT-POINT-LIST en 1e-3))
(setq lst (mapcar '(lambda (x) (list (car x) (cadr x))) lst))
(while lst
(setq head (car lst)
tmp (cons head tmp)
lst (vl-remove-if
'(lambda (pt) (equal pt head 1e-6))
(cdr lst)
) ;_ end of vl-remove-if
) ;_ end of setq
) ;_ end of while
(setq lst (reverse tmp)) ;_ end of setq
(ACET-SS-ZOOM-EXTENTS (ACET-LIST-TO-SS (list en)))
(command "_.Zoom" "0.95x") 
(if (setq ss (ssget "_CP" lst))
(sssetfirst ss ss)
) ;_ end of if
) ;_ end of progn
) ;_ end of if
) ;_ end of defun 
(princ "\nType ICS")

 but if you want to select on multiple circle at once time you ca create a repeat loop and use ssget function.

Message 3 of 18
artur_isa
in reply to: taiki84

i have 4000 circles that i need to select what inside them.

i want to "select similar" all the circles, and run this lisp so it selects everything inside at once.

possible??

Message 4 of 18
hmsilva
in reply to: artur_isa

Hi Artur,

the code you have posted, was created by VVA and is destined to select objects 'inside' a *POLYLINE, not a CIRCLE...


@artur_isa wrote:

i have 4000 circles that i need to select what inside them.

i want to "select similar" all the circles, and run this lisp so it selects everything inside at once.

possible??


Yes, it will be possible if the boundary CIRCLES have similar properties, as LAYER or COLOR or RADIUS or LINETYPE and unique, not common to the objects to be selected.

 

Note that using a code to select objects 'inside' 4000 circles  will always be an extremely slow code because to select objects 'inside' a circular object we'll have to calculate many points for each CIRCLE to pass the points to the selection method and will be multiplied by 4000, so it will be sloowww...

 

Henrique
 

EESignature

Message 5 of 18
artur_isa
in reply to: hmsilva

same circles scattered all over the dwg, 

how can i do it? the lisp works on one circle but wont let me choose more than one circle

 

what to change??

Message 6 of 18
hmsilva
in reply to: artur_isa


@artur_isa wrote:

same circles scattered all over the dwg, 

how can i do it? the lisp works on one circle but wont let me choose more than one circle

 


If it works, the object is not a CIRCLE, must be a '*POLYLINE'!!!

 

Post a sample dwg with a few objects (boundaries and objects within the borders) in order we can see the objects properties...

 

Henrique

 

 

 

EESignature

Message 7 of 18
marko_ribar
in reply to: hmsilva

Henrique, (ACET-GEOM-OBJECT-POINT-LIST curveename 1e-3) works on any curve among them and on CIRCLES... So taiki's posted revision is fine for a single CIRCLE, and yes for 4000 of them it would be significally slooowww... If we could know proper filter to apply to selection (ssget) function to aquire correct CIRCLES then iteration of sel.set items would be an answer with the rest of code similar to this posted above...

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 8 of 18
hmsilva
in reply to: marko_ribar

Hi Marko,

 

I know that 'ACET-GEOM-OBJECT-POINT-LIST' works on any curve, but the VVA's original code don't, because it only accepts as valid entity "*POLYLINE", the commented code posted by taiki84 works...

 

Henrique

EESignature

Message 9 of 18
artur_isa
in reply to: hmsilva

layer 4601 small circles on lines (an example)

 

possible to make the lisp work like the tlen lisp?

you just select all the lines you want to count length and it counts

so possible to make this lisp to work on current selection? i.e. i choose 300 circles or 4000 circles run the lisp and it selects everything inside the circles i chose?

;|

TLEN.LSP - Total LENgth of selected objects
(c) 1998 Tee Square Graphics

|;

(defun C:TLEN (/ ss tl n ent itm obj l)
(setq ss (ssget)
tl 0
n (1- (sslength ss)))
(while (>= n 0)
(setq ent (entget (setq itm (ssname ss n)))
obj (cdr (assoc 0 ent))
l (cond
((= obj "LINE")
(distance (cdr (assoc 10 ent))(cdr (assoc 11 ent))))
((= obj "ARC")
(* (cdr (assoc 40 ent))
(if (minusp (setq l (- (cdr (assoc 51 ent))
(cdr (assoc 50 ent)))))
(+ pi pi l) l)))
((or (= obj "CIRCLE")(= obj "SPLINE")(= obj "POLYLINE")
(= obj "LWPOLYLINE")(= obj "ELLIPSE"))
(command "_.area" "_o" itm)
(getvar "perimeter"))
(T 0))
tl (+ tl l)
n (1- n)))
(alert (strcat "Total length of selected objects is " (rtos tl)))
(princ)
)

 

Message 10 of 18
marko_ribar
in reply to: artur_isa

DWG you posted contains blocks that have circle... Those are not CIRCLE entities and now I don't know what would be the best way to accomplish your task... Maybe if you just want to select those lines that are passing through those blocks, just make list of points with insertions of all selected blocks and then use (setq ss (ssadd))... (foreach pt ptlst (ssadd (ssname (ssget pt) 0) ss))

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 11 of 18
artur_isa
in reply to: marko_ribar

to be honest, i have midpoint coodrinates of the lines i want to choose a list of 4000 lines i specificly need to select

 

any lisp to select by coordinates?

Message 12 of 18
marko_ribar
in reply to: artur_isa

Then, you don't need more than this :

 

(defun c:selbyptlst ( / ptlst ss )
  (setq ptlst '((0.0 0.0 0.0) (1.0 1.0 0.0) (2.0 2.0 0.0))) ;;; => Your 4000 coordinates in variable ptlst
  (setq ss (ssadd))
  (foreach pt ptlst
    (ssadd (ssname (ssget "_C" pt pt) 0) ss)
  )
  (sssetfirst nil ss)
  (princ)
)

 HTH, M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 13 of 18
artur_isa
in reply to: marko_ribar

You mean like this? because i did so and it didnt work? 

(setq ptlst '((X.X Y.Y Z.Z) (X2.X2 Y2.Y2 Z2.Z2))) ;;; => Your 4000 
Message 14 of 18
hmsilva
in reply to: artur_isa

As a 'demo' and coded from your sample dwg.

If you want the user to select the blocks, remove the "_X" from the first ssget function...

(defun c:demo (/ blk ent i lgt n osm pt ss ss1 tlgt)
  (vl-load-com)
  (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "Water_Pipe_section") (66 . 1))))
    (progn
      (setq osm (getvar 'OSMODE))
      (setvar 'OSMODE 0)
      (command "_.zoom" "_E")
      (command "_.zoom" 0.9)
      (setq tlgt 0.0)
      (repeat (setq i (sslength ss))
        (setq blk (entget (ssname ss (setq i (1- i))))
              pt  (cdr (assoc 10 blk))
        )
        (if (setq ss1 (ssget "_C" pt pt '((0 . "LWPOLYLINE"))))
          (repeat (setq n (sslength ss1))
            (setq ent  (ssname ss1 (setq n (1- n)))
                  lgt  (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent))
                  tlgt (+ lgt tlgt)
            )
          )
        )
      )
      (setvar 'OSMODE osm)
      (command "_.zoom" "_P")
      (command "_.zoom" "_P")
      (princ (strcat "\nTotal  length: " (rtos tlgt)))
    )
  )
  (princ)
)

 

Henrique

EESignature

Message 15 of 18
artur_isa
in reply to: hmsilva

Let me describe my problem in bigger detail

i have a dwg plan of a whole city and i need to choose specific polylines (only 4000 out of 16000) that i have given coordinates from excel 

and cut them to another file.

any lisp to help? 

 

my idea was to spawn circles at the coordinates and do the lisp that chooses everything inside a circle, but i cant select all the circles at once with that lisp

any ideas??

Message 16 of 18
marko_ribar
in reply to: artur_isa

Like Henrique has explained... To select only specific blocks (mid points), remove "_X" from first (ssget) function call...

This is the same code as Henrique offered, only difference is that it should select those entities that pass through those blocks (mid points) so you can cut them to another file...

 

(defun c:demo ( / blk ent i n osm pt s ss ss1 )
  (setq s (ssadd))
  (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "Water_Pipe_section") (66 . 1))))
    (progn
      (setq osm (getvar 'OSMODE))
      (setvar 'OSMODE 0)
      (command "_.zoom" "_E")
      (command "_.zoom" 0.9)
      (repeat (setq i (sslength ss))
        (setq blk (entget (ssname ss (setq i (1- i))))
              pt  (cdr (assoc 10 blk))
        )
        (if (setq ss1 (ssget "_C" pt pt))
          (repeat (setq n (sslength ss1))
            (setq ent  (ssname ss1 (setq n (1- n))))
            (ssadd ent s)
          )
        )
      )
      (setvar 'OSMODE osm)
      (command "_.zoom" "_P")
      (command "_.zoom" "_P")
      (sssetfirst nil s)
    )
  )
  (princ)
)

 Regards...

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 17 of 18
hmsilva
in reply to: artur_isa


@artur_isa wrote:

layer 4601 small circles on lines (an example)

 

possible to make the lisp work like the tlen lisp?

...

 


Layer 4601 don't have circles, have blocks...

 

The 'demo' work like the tlen lisp...

 


@artur_isa wrote:

Let me describe my problem in bigger detail

i have a dwg plan of a whole city and i need to choose specific polylines (only 4000 out of 16000) that i have given coordinates from excel 

and cut them to another file.

any lisp to help? 

 

my idea was to spawn circles at the coordinates and do the lisp that chooses everything inside a circle, but i cant select all the circles at once with that lisp

any ideas??


Attach a 'real' sample file and if your excel file with the coordinates, only have the desired coordinates, save as .csv file and erase the rest of the coordinates, leaving only a few at the beginning of the file and attach the .csv file also...

'Everithing' is only one 'lwpolyline', correct?

 

Henrique

EESignature

Message 18 of 18
stevor
in reply to: artur_isa

1. Post the file that has this list of midpoints, as a start.

2. Sometimes the ssget "c" process needs to make a small box,

ie 2 points, tht straddles the intended point.

S

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

Post to forums  

Autodesk Design & Make Report

”Boost