Author Topic: Duplicate geometry based on size  (Read 1758 times)

0 Members and 1 Guest are viewing this topic.

quamper

  • Guest
Duplicate geometry based on size
« on: February 06, 2008, 02:20:41 PM »
What I'm wanting to do is when I select some objects if one side is less than a certain length say 6" I want to duplicate it and assign a different layer to the duplicate copy.

It's always going to be a closed polyline that I'm selecting.

Here's my amazing code so far :-D

It's actually my first Lisp program as I'm more familiar with the .Net side of things, I just figured that was overkill in this instance and it would be a good idea to have a basic understanding of lisp. It's just a basic quick and dirty program to speed up some monotonous stuff I setup on a routine basis and what I've got works fine. I was just wondering/hoping I could evaluate the length of the parts I'm selecting rather than going back after the fact.

Code: [Select]
(defun c:komoprep ( / ss )
(command "chprop" "all" "" "color""bylayer""")
(setq ss (ssget "x" '((-4 . "<OR")(0 . "LINE")(0 . "ARC")(-4 . "OR>"))))
(if (/= ss nil)
(command "pedit" "m" ss """y" "")
)

(command "pedit" "m" "all" "" "j" """")

(setq ss (ssget "x" '((0 . "CIRCLE")(40 . 0.09375))))
(if (/= ss nil)
(command "chprop" ss "" "layer""SCREW_HOLES""")
)

(setq ss (ssget "x" '((0 . "CIRCLE")(-4 . ">")(40 . 0.094)(-4 . "<")(40 . 0.099))))
(if (/= ss nil)
(command "chprop" ss "" "layer""LINE_BORING""")
)

(setq ss (ssget "x" '((0 . "CIRCLE")(-4 . ">")(40 . 0.1))))
(if  (/= ss nil)
(command "chprop" ss "" "layer""SMALL_HOLES""")
)

(prompt "\nSelect Plywood parts")
(setq ss (ssget))
(if (/= ss nil)
(command "chprop" ss "" "layer""OUTSIDE_PLY""")
)

(prompt "\nSelect MDF parts: ")
(setq ss (ssget))
(if (/= ss nil)
(command "chprop" ss "" "layer""OUTSIDE_MDF""")
)
(princ)
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Duplicate geometry based on size
« Reply #1 on: February 06, 2008, 03:04:15 PM »
Just a little tweak of your lisp.
Code: [Select]
(defun c:komoprep (/ ss)
  (command "chprop" "all" "" "color" "bylayer" "")


  (if (setq ss (ssget "x" '((0 . "LINE,ARC"))))
    (command "pedit" "m" ss "" "y" "")
  )

  (command "pedit" "m" "all" "" "j" "" "")


  (if (setq ss (ssget "x" '((0 . "CIRCLE") (40 . 0.09375))))
    (command "chprop" ss "" "layer" "SCREW_HOLES" "")
  )


  (if (setq ss (ssget "x" '((0 . "CIRCLE") (-4 . ">") (40 . 0.094)
                            (-4 . "<") (40 . 0.099))))
    (command "chprop" ss "" "layer" "LINE_BORING" "")
  )


  (if (setq ss (ssget "x" '((0 . "CIRCLE") (-4 . ">") (40 . 0.1))))
    (command "chprop" ss "" "layer" "SMALL_HOLES" "")
  )

  (prompt "\nSelect Plywood parts")
  (if (setq ss (ssget))
    (command "chprop" ss "" "layer" "OUTSIDE_PLY" "")
  )

  (prompt "\nSelect MDF parts: ")
  (if (setq ss (ssget))
    (command "chprop" ss "" "layer" "OUTSIDE_MDF" "")
  )
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

quamper

  • Guest
Re: Duplicate geometry based on size
« Reply #2 on: February 06, 2008, 03:07:18 PM »
Just a little tweak of your lisp.

Thank you!

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Duplicate geometry based on size
« Reply #3 on: February 06, 2008, 03:25:28 PM »
Maybe something like this for the rectangle.
Note: does not rule out parallelograms!
Code: [Select]
(defun c:test (/ ss lst elst vlst result)
  (prompt"\nSelect closed plines.")
  (setq ss (ssget '((0 . "LWPOLYLINE,POLYLINE")(-4 . "&")(70 . 1))))

  ;|
  ;; or get all closed plines
  (setq ss (ssget "ALL" '((0 . "LWPOLYLINE,POLYLINE")(-4 . "&")(70 . 1))))

  ;; or get all closed plines on a layer in current space
  (setq ss (ssget "ALL" (list '(0 . "LWPOLYLINE,POLYLINE")'(-4 . "&")'(70 . 1)
                              (cons 8 LayName) (cons 410 (getvar "ctab")))))

  |;
 
  ;;  create a list of all objects in the selection set
  (setq lst (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))

  (foreach pl lst
    (setq elst (entget pl))
    (if (and (= (cdr(assoc 90 elst)) 4) ; has 4 vertex
             (setq vlst (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= 10 (car x))) elst)))
             (or (equal (distance (car vlst)(cadr vlst)) 6.0 0.0001)
                 (equal (distance (cadr vlst)(caddr vlst)) 6.0 0.0001)
             )
        )
      ;;  got a closed pline with one side = to 6 units
      (setq result (cons pl result))
    )
  )
  (if result
      (print (strcat "Got some. " (itoa (length result))))
      (print "Got Nothing matching the length specified.")
  )
 
  (princ)
)
« Last Edit: February 06, 2008, 04:10:31 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Duplicate geometry based on size
« Reply #4 on: February 06, 2008, 04:11:30 PM »
Updated code with an actual working routine, not just sample code.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.