COND based on selection in model space LISP

COND based on selection in model space LISP

eharrisonTZS2M
Enthusiast Enthusiast
916 Views
13 Replies
Message 1 of 14

COND based on selection in model space LISP

eharrisonTZS2M
Enthusiast
Enthusiast

i am trying to write a LISP where i select a LWPOLYLINE, ELLIPSE, or CIRCLE, based on what is manually pasted at the 0,0 point in model space.  when running "TDXF" command, the only command that works appropriately will be the first condition listed under "COND"...so below, ((= ss5)(c:ellipsedxf)) is the only command that will work correctly. which  ever condition is listed first will run it's respective program listed below in full. i can manually type out each command individually to get their respective commands in full without any issues. 

 

something tells me i'm not listing the initial "setq" for ss1, ss4, or ss5 appropriately, or the COND is not set up correctly.

 

can someone give me some guidance on how to set up the COND?

 

(defun C:TDXF ()
 
 
(setq ss4(ssget "_X" '((0 . "LWPOLYLINE")))
  );end setq
 
(setq ss5(ssget "_X" '((0 . "ELLIPSE")))
    );end setq
 
(setq ss1(ssget "_X" '((0 . "CIRCLE")(-4 . ">=")(40 . 2.0)))
    );end setq
 
(cond
((= ss5)(c:ellipsedxf))
((= ss4)(c:rectangledxf))
((= ss1)(c:circledxf))
);end cond
 
 
 
(defun c:rectangledxf ()
(setq ss4(ssget "_X" '((0 . "LWPOLYLINE")))
);end setq
(command "._change" ss4 "" "p" "LA" "MY-LAYER NUMBER 1" "")
(command "_.scale" "all" "" "0,0" "25.4")
(command "._zoom" "e")
);end rectangledxf
 
(defun C:circledxf ()
(setq ss1(ssget "_X" '((0 . "CIRCLE")(-4 . ">=")(40 . 2.0)))
);end setq
(command "._change" ss1 "" "p" "LA" "MY-LAYER NUMBER 2" "")
(command "_.scale" "all" "" "0,0" "25.4")
(command "._zoom" "e")
 
);end circledxf
 
(defun c:ellipsedxf ()
(setq ss5(ssget "_X" '((0 . "ELLIPSE")))
);end setq
(command "._change" ss5 "" "p" "LA" "MY-LAYER NUMBER 2" "")
(command "_.scale" "all" "" "0,0" "25.4")
(command "._zoom" "e")
);end ellipsedxf
 
);end
0 Likes
Accepted solutions (1)
917 Views
13 Replies
Replies (13)
Message 2 of 14

SAPER59
Advocate
Advocate
This should be the cond sintaxis for you
If more than one condition matches, ofcourse first one will be considered, otherwise you should do an if condition
 
(cond
( ss5 (c:ellipsedxf))
( ss4 (c:rectangledxf))
(ss1 (c:circledxf))
);end cond
 
 
(if ss5 (c:ellipsedxf))
( if ss4 (c:rectangledxf))
(if ss1 (c:circledxf))
 
0 Likes
Message 3 of 14

paullimapa
Mentor
Mentor

You could also consider passing the selection objects as an argument onto each of the lisp functions instead of having to select them again. For example, 

; rectangledxf function with ss-arg as argument
(defun rectangledxf (ss-arg)
  (command "._change" ss-arg "" "_p" "_LA" "MY-LAYER NUMBER 1" "")
  (command "_.scale" "_all" "" "0,0" "25.4")
  (command "._zoom" "_e")
);end rectangledxf

(if (setq ss4(ssget "_X" '((0 . "LWPOLYLINE")))) ;end setq
 (rectangledxf ss4) ; run rectangle function passing ss4 as argument
)

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 4 of 14

komondormrex
Mentor
Mentor

hey there,

better be written like that

 

 

(defun C:TDXF ()
	(defun change_sset (sset)
		(command "._change" sset "" "p" "LA" "MY-LAYER NUMBER 1" "")
		(command "_.scale" "all" "" "0,0" "25.4")
		(command "._zoom" "e")
	)
	(or
		(setq sset (ssget "_X" '((0 . "LWPOLYLINE"))))
		(setq sset (ssget "_X" '((0 . "ELLIPSE"))))
		(setq sset (ssget "_X" '((0 . "CIRCLE") (-4 . ">=") (40 . 2.0))))
	)
	(if sset (change_sset sset))
)

 

 

0 Likes
Message 5 of 14

paullimapa
Mentor
Mentor

@eharrisonTZS2M  Keep in my that if you run all three routines that means ALL objects will be scaled 25.4 three times


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 14

komondormrex
Mentor
Mentor

i did not actually look what are all three *dxf commands are supposed to do. it appeared they are doing same set of commands. so i corrected the code to proper functioning. however the code does miss a cond statement at all.

0 Likes
Message 7 of 14

paullimapa
Mentor
Mentor

Perhaps OP wants to change layer of each of the selection sets if any and then run scale all & zoom once?  


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 8 of 14

eharrisonTZS2M
Enthusiast
Enthusiast

There will never be a time where the LWPOLYLINE, CIRCLE, or ELLIPSE will be in the same drawing. That is why I’m trying to use the condition. Also, please note that the ELLIPSE and CIRCLE will go to “layer-1” while the LWPOLYLINE will go to “layer-2”. Thus the need for separate commands.

 

Also, I’d like to keep each command separate from each other “circledxf, ellipsedxf, rectangledxf” because I intend on adding more commands under each section that will do different things based on the shape being used.

0 Likes
Message 9 of 14

Kent1Cooper
Consultant
Consultant

@eharrisonTZS2M wrote:

There will never be a time where the LWPOLYLINE, CIRCLE, or ELLIPSE will be in the same drawing. ....


Then I would do it something like this:

 

(defun C:TDXF ()
  (cond
    ((setq ss4 (ssget "_X" '((0 . "LWPOLYLINE")))); are there any Polylines?
      (c:rectangledxf); then run this command
    ); end Polyline condition
    ((setq ss5(ssget "_X" '((0 . "ELLIPSE")))); no Polylines -- are there any Ellipses?
      (c:ellipsedxf); then run this command
    ); end Ellipse condition
    ((setq ss1(ssget "_X" '((0 . "CIRCLE")(-4 . ">=")(40 . 2.0))))
      ; no Polylines or Ellipses -- are there any Circles of at least 2-drawing-unit radius?
      (c:circledxf); then run this command
    ); end Circle condition
  ); end cond
)
 
You can have those object-type command definitions [without their object selection -- that's already done] included within the definition of the over-arching command, or loaded separately.
 
But I am a little confused by some things.  If there are any Polylines at all, is it to be assumed [from the command name] that they will all be rectangles?  Does that mean there would never be any non-rectangular Polylines, and would it matter if there are?  And if there are any Circles at least 2 units in radius, it will Scale all Circles, of any radius?  Could there ever be Circles, but none at least that big?  Can we assume from the fact that all the object-type commands Scale all objects in the drawing that the drawing will always consist of only the one object type?
Kent Cooper, AIA
0 Likes
Message 10 of 14

eharrisonTZS2M
Enthusiast
Enthusiast

Now that you mention it, there could be times where there could be a polyline and it would NOT be a rectangle.

 

Therefore, I will need a 4th command for that situation. Could “POLYLINE” be used for shapes other than rectangles, circles, or ellipses?

 

If so, I imagine it will end up looking like the circle and ellipse command, replacing the word “CIRCLE” or”ELLIPSE” with “POLYLINE”. The layer for the POLYLINE would also change to the same layer that the “CIRCLE” or “ELLIPSE option will be changing to. I’ll use “layer 1” and it’s green for an example…underneath those commands, I have another custom code (not listed in this forum) that will make a box around that circle, ellipse, or polyline and it will make that box “layer 2, red”.

Then, would the command for the rectangles need to use LWPOLYLINE? If so, within its command, it will make the layer for the rectangle/LWPOLYLINE the same layer as the box created in the previous paragraph, “layer 2, red”.

 

 

As for the concern about circles, I also have separate code, not in this forum, that will make circles smaller than what I have listed above, a separate layer. And after scaling everything by 25.4, will take those smaller circles and give them all the same diameter automatically. So I’ve got that all worked out. 

 

 

0 Likes
Message 11 of 14

paullimapa
Mentor
Mentor

since it's possible that a drawing can contain both closed plines as well as open plines then you don't want to run two separate functions that contain the SCALE command


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 12 of 14

Kent1Cooper
Consultant
Consultant

If you want to see code that figures out whether a Polyline is a rectangle, open MakeMore.lsp with its MM command >here<.  [It's attached in other topics, but I think that is the most current version.]  That knows whether a selected Polyline is rectangular and closed [whether or not it's orthogonally oriented, and whether it's "heavy" or "lightweight"], so it can offer RECTANG as a default command to bring up, which the ADDSELECTED command can't do.

 

Would you be capable of lifting its rectangle-checking elements and putting them into your code?

Kent Cooper, AIA
0 Likes
Message 13 of 14

eharrisonTZS2M
Enthusiast
Enthusiast

Awesome! Thanks for the .LSP. I’m pretty sure I can get the rectangle info from that and put it into my code.

 

It’ll be a few days before I can implement any of these changes as I don’t have access to my work PCuntil after the first of the new year.

 

I’ll reply then with how things turned out.

0 Likes
Message 14 of 14

eharrisonTZS2M
Enthusiast
Enthusiast
Accepted solution

thanks to all!!!

 

i finally got it to work how i wanted. i had to write separate lisp files. for some reason, when i put all the programs under 1 lisp, it kept failing. i also like the separate lisp files. it keeps things cleaner for me to look at it all

 

i run "TDXF", it determines shape and program from there...the only thing i have to do manually is select the polyline for autocad to determine if it's a rectangle or polyline then hit "enter". i'm sure i could remove a lot of information under "polylinedxf" but i took the recommended MM.LSP and worked my way backwards removing as much as i could until i didn't find any more errors from me removing code. there is probably a way to automate and make this portion shorter, but i'm content after working on this for so long.

 

-----------------------------------------------

 

(defun C:TDXF ()
 
(command "._PASTECLIP" "0,0")
 
(setq ss5(ssget "_X" '((0 . "ELLIPSE")))
);end setq
 
(setq ss1(ssget "_X" '((0 . "CIRCLE")(-4 . ">=")(40 . 2.0)))
);end setq
 
  (cond
(ss1(c:circledxf))
(ss5(c:ellipsedxf))
(T(c:polylinedxf))
  ); end cond
 
(command "_.purge" "_all" "*" "_no")
 
(if (setq fileName (getstring T "\nEnter a file name: "))
   (vla-saveas
     (vla-get-activedocument (vlax-get-acad-object))
     (strcat "F:\\Engineering\\Program_Items\\" fileName ".dxf")
     ac2010_dxf)
   )
 (princ)
 
);end
 
--------------------
 
(defun C:circledxf ()
 
(vlax-for layout (vla-get-layouts(vla-get-ActiveDocument (vlax-get-acad-object)))
(if (/= (vla-get-name layout) "Model")(vla-delete layout)))
 
(setq ss1(ssget "_X" '((0 . "CIRCLE")(-4 . ">=")(40 . 2.0)))
);end setq
 
(setq ss3(ssget "_X" '((0 . "CIRCLE")(-4 . "<=")(40 . 2.0)))
);end setq
 
(command "._change" ss1 "" "p" "LA" "Geometry_0" "")
(command "._change" ss3 "" "p" "LA" "V_DrillFF_3" "")
(command "_.scale" "all" "" "0,0" "25.4")
 
     (if (and (setq d (abs 3))
      (setq d (/ d 2.))
      (setq ss (ssget "_X" '((8 . "V_DrillFF_3"))))
      )
       (repeat (setq i (sslength ss))
         (setpropertyvalue (ssname ss (setq i (1- i))) "Radius" d)))
 
  (defun obb (ent); = Object's Bounding Box corners
    (vla-getboundingbox (vlax-ename->vla-object ent) 'minpt 'maxpt)
    (setq
      oLL (vlax-safearray->list minpt); Object's Lower Left
      oUR (vlax-safearray->list maxpt); Object's Upper Right
    ); setq
  ); defun -- obb
  (vl-load-com)
  ;;(prompt "\nTo draw the Smallest Rectangle around them,")
  (setq ss (ssget "_X" '((8 . "Geometry_0"))))
  (obb (ssname ss 0))
  (setq LL oLL UR oUR); initial overall LL & UR [of first object]
  (ssdel (ssname ss 0) ss)
  (repeat (sslength ss)
    (obb (ssname ss 0))
    (setq
      LL (mapcar 'min oLL LL); least of each component
      UR (mapcar 'max oUR UR); greatest of each component
    ); setq
    (ssdel (ssname ss 0) ss)
  ); repeat
  (command "_.rectangle" "_none" LL "_none" UR)
  (princ)
 
(setq ss2(ssget "_L")
);end setq
(command "._change" ss2 "" "p" "LA" "ProcPart_31" "")
 
(command "._zoom" "e")
 
);end circledxf
 
--------------------------------------------
 
(defun c:ellipsedxf ()
 
(vlax-for layout (vla-get-layouts(vla-get-ActiveDocument (vlax-get-acad-object)))
(if (/= (vla-get-name layout) "Model")(vla-delete layout)))
 
(setq ss5(ssget "_X" '((0 . "ELLIPSE")))
);end setq
 
(setq ss3(ssget "_X" '((0 . "CIRCLE")(-4 . "<=")(40 . 2.0)))
);end setq
 
(command "._change" ss5 "" "p" "LA" "Geometry_0" "")
(command "._change" ss3 "" "p" "LA" "V_DrillFF_3" "")
(command "_.scale" "all" "" "0,0" "25.4")
 
     (if (and (setq d (abs 3))
      (setq d (/ d 2.))
      (setq ss (ssget "_X" '((8 . "V_DrillFF_3"))))
      )
       (repeat (setq i (sslength ss))
         (setpropertyvalue (ssname ss (setq i (1- i))) "Radius" d)))
 
  (defun obb (ent); = Object's Bounding Box corners
    (vla-getboundingbox (vlax-ename->vla-object ent) 'minpt 'maxpt)
    (setq
      oLL (vlax-safearray->list minpt); Object's Lower Left
      oUR (vlax-safearray->list maxpt); Object's Upper Right
    ); setq
  ); defun -- obb
  (vl-load-com)
  ;;(prompt "\nTo draw the Smallest Rectangle around them,")
  (setq ss (ssget "_X" '((8 . "Geometry_0"))))
  (obb (ssname ss 0))
  (setq LL oLL UR oUR); initial overall LL & UR [of first object]
  (ssdel (ssname ss 0) ss)
  (repeat (sslength ss)
    (obb (ssname ss 0))
    (setq
      LL (mapcar 'min oLL LL); least of each component
      UR (mapcar 'max oUR UR); greatest of each component
    ); setq
    (ssdel (ssname ss 0) ss)
  ); repeat
  (command "_.rectangle" "_none" LL "_none" UR)
  (princ)
 
(setq ss2(ssget "_L")
);end setq
(command "._change" ss2 "" "p" "LA" "ProcPart_31" "")
   
(command "._zoom" "e")
 
);end ellipsedxf
 
----------------------------------
 
(defun C:polylinedxf
 
  (/ *error* *esel *pcn *poly *hatch *ed cmde ent data typ P1 P2 P3 parpt
  eq42 cl I1 S1 R1 S2 I2 tj tj2 R2 thov R3 twov E1 tcont E2 tlist tbang pdm)
    ; Initial-capital variables are for Point/Integer/String/Real/Entity, to lessen quantity of
    ; variable names; most used in more than one section, sometimes for different purposes
;
  (defun *esel (); Entity SELection by User [verb-noun operation or multiple pre-selected objects]
    (while    
(not (setq ent (car (entsel "\nSelect object: "))))
      (prompt "\nNothing selected:")
    ); while
  ); defun - *esel
;
  (defun *pcn (); = Prompt Command Name [display what command was invoked, without double first prompt]
    ; when command name is same as object type or Polyline sub-type
    (prompt
      (strcat
        "\n"
        (cond
          (S2 (strcase S2))
            ; LWPolyline, Leader, PolygonMesh, Region, 3Dsolid, Body subtypes, Divide/Measure for Point
          (typ); none-of-the-above
        ); cond
        "  "
      ); strcat
    ); prompt
  ); defun - *pcn
;
  (defun *poly (); shared between LWPolyline & 2D Polyline types
    (initget "PLine Rectangle POlygon Donut Cloud Boundary Sketch")
    (setq
      S2
        (getkword
          (strcat
            "\nPolyline Type [PLine/Rectangle/POlygon/Donut/Cloud/Boundary/Sketch] <"
            S1
            ">: "
          ); strcat
        ); getkword
      S2 (cond (S2) (S1)); use User entry, or default for Enter
    ); setq
 
    (cond; variety of Polyline
      ((= S2 "Rectangle")
        (C:Rectangledxf)
      ); Rectangle variety
 
      ((= S2 "POlygon")
        (setvar 'polysides (if (> I1 2) I1 4))
        (setvar 'cmdecho cmde)
        (command "_.polygon")
          (while (> (getvar 'cmdactive) 0) (command pause))
        (vlax-put (vlax-ename->vla-object (entlast)) 'ConstantWidth (getvar 'plinewid))
          ; Polygon doesn't honor width -- assign current [selected item's] width to new Polygon
      ); POlygon variety
 
      ((= S2 "Donut")
        (setq R1; donut diameter at centerline
          (distance (vlax-curve-getStartPoint ent) (vlax-curve-getPointAtParam ent 1))
        ); setq
        (setvar 'donutid (- R1 (getvar 'plinewid)))
        (setvar 'donutod (+ R1 (getvar 'plinewid)))
        (*pcn)
        (command "_.donut")
      ); Donut variety
      ((= S2 "Cloud")
        (prompt "\nREVCLOUD ")
        (if (= S1 "Cloud"); as determined for default offering
          (progn ; then
            (setq R1 (distance (vlax-curve-getStartPoint ent) (vlax-curve-getPointAtParam ent 1)))
              ; arc min/max lengths calculated from data; adjust multipliers as desired
            (command "_.revcloud" "_arc" (* R1 0.9) (* R1 1.1))
          ); progn
          (command "_.revcloud"); else - Cloud option chosen from other kind of selected Pline
        ); if
      ); Revcloud variety
      ((= S2 "Boundary")
        (setvar 'hpbound 1)
        (*pcn)
        (command "_.boundary")
      ); Boundary variety
      ((= S2 "Sketch")
        (setvar 'skpoly 1); Polyline variety
        (*pcn)
        (command "_.sketch")
      ); Sketch variety
      (T (prompt "\nPLINE ") (C:POLYLINEDXF-STEP2)); ordinary-PLine variety
    ); cond - variety of LWPoly
  ); defun - *poly
;
  (defun *ed (dxf); = Entity Data value associated with DXF code number
    (cdr (assoc dxf data))
  ); defun - *ed
;
  (cond ; OBJECT SELECTION
    ( (and
        (setq ss (ssget "_I")); something pre-selected
        (= (sslength ss) 1); only one object
      ); and
      (setq ent (ssname ss 0))
    ); first condition [single pre-selected object]
    ( (ssget "_I"); more than one object selected
      (sssetfirst nil); un-select multiple objects
      (*esel); User select
    ); second condition
    ((*esel)); User select [nothing pre-selected]
  ); cond
;
  (setq
    data (entget ent)
    typ (*ed 0)
  ); setq
  ; Warning & reset recommendation if any overrides not Bylayer or default:
(cond; begin OVERARCHING TEST for each object type
;
    ((wcmatch typ
      "LINE,XLINE,RAY,SOLID,3DFACE,ARC,CIRCLE,ELLIPSE,SPLINE,IMAGE,WIPEOUT,TOLERANCE")
      (*pcn)
      (command (strcat "_." typ))
    ); CATCH-ALL condition for object types whose command names are the same as their 'typ' values,
      ; and which don't need any other information extracted to set variables, nor have other complications
      ;;;;; pull IMAGE out and offer SUPERHATCH option, perhaps only if part of a Group?
      ;;;;; pull SOLID,3DFACE,WIPEOUT out and offer TEXTMASK option?
;
    ((= typ "LWPOLYLINE")
      (if (= (getvar 'plinetype) 0) (setvar 'plinetype 2))
        ; in case set at 0 [old-style "heavy" 2D type]; value of 1 can remain [new ones still lightweight];
        ; assumes no desire to return it to 0 - add that resetting/option/recommendation, if desired
      (if (assoc 43 data); has global width
        (setvar 'plinewid (*ed 43)); then - match it
        (setvar 'plinewid 0); else - remove current width if non-zero
      ); if
      (defun parpt (par); find Point at Parameter for Polyline type tests
        (vlax-curve-getPointAtParam ent par)
      ); defun - parpt
      (defun eq42 (val / pdata); find whether *all* bulge factors [(assoc 42) entries] have specified value
        (setq pdata data)
        (while (equal (cdr (assoc 42 pdata)) val 1e-6); can be + or -
          (setq pdata (cdr (member (assoc 42 pdata) pdata))); remainder after this 42 entry
        ); while
        (not (assoc 42 pdata)); returns T if they were all equal [none left]
      ); defun - eq42
      (setq
        cl (vlax-curve-isClosed ent)
        I1 (*ed 90); number of vertices for type tests & to set 'polysides
        S1 ; LWPolyline-making command default
          (cond
            ( (and
                (= I1 4)
                cl
                (assoc 43 data); global width
                (eq42 0.0); all straight-line segments
                (equal (distance (parpt 0) (parpt 1)) (distance (parpt 2) (parpt 3)) 1e-8); opposite sides equal lengths
                (equal (distance (parpt 1) (parpt 2)) (distance (parpt 3) (parpt 0)) 1e-8)
                (equal (rem (abs (- (angle (parpt 0) (parpt 1)) (angle (parpt 1) (parpt 2)))) pi) (/ pi 2) 1e-8)
                  ; right angle first corner
              ); and
              "Rectangle"
            ); Rectangle condition
;;;;; Identifies only four-sided square-cornered Rectangles; Rectangle command has options independent
;;;;; of similar options for general drawing: [Chamfer/Elevation/Fillet/Thickness/Width].
;;;;; Polyline with 8 vertices, 2nd & 6th segments same length, 4th & 8th segments same length, odd-numbered
;;;;; ones all same length, could be Rectangle with Fillet/Chamfer option; if odd-numbered segments have
;;;;; (42 . 0.414214), Fillet [90-degree arc bulge factor]; if (eq42 0.0), Chamfer.
;;;;;  ***Don't know where those options are stored, or how to set them as defaults programmatically.***
            ( (and
                (> I1 2)
                cl
                (member '(43 . 0.0) data); global width = 0
                (eq42 0.0); all straight-line segments
                (equal ; first two and last two segments, at least, all same length
                  (setq R1 (distance (parpt 0) (parpt 1))); first segment length
                  (distance (parpt 1) (parpt 2)); second
                  1e-8
                ); equal
                (equal (distance (parpt (- I1 2)) (parpt (1- I1))) R1 1e-8); next-to-last
                (equal (distance (parpt (1- I1)) (parpt 0)) R1 1e-8); last
              ); and
              "POlygon"
            ); POlygon condition [does not check for equal angles]
            ( (and
                (= I1 2)
                cl
                (assoc 43 data); global width
                (or (eq42 1.0) (eq42 -1.0))
                  ; both full-semi-circle arc segments in same direction, CCW or CW
              ); and
              "Donut"
            ); Donut condition
            ( (and
                (assoc 43 data); global width
                (or
                  (and
                    cl
                    (or (eq42 0.520567) (eq42 -0.520567)); all Revcloud-type arc segments
                  ); and
                  (and
                    (not cl)
                    (setq data (reverse (cddr (reverse data))))
                      ; removes last (42) entry, which is 0 for open Revclouds.  Then:
                    (or (eq42 0.520567) (eq42 -0.520567)); all Revcloud-type remaining
                  ); and
                ); or
              ); and
              "Cloud"
            ); Cloud condition
            ("PLine"); none of the above [no default determination for Boundary or Sketch]
          ); cond & S1
      ); setq
      (*poly); subroutine shared with 2D Polyline type
    ); cond - LWPoly object type
;
    ((= typ "POLYLINE")
      (setq S2 (substr (cdr (assoc 100 (reverse data))) 5))
        ; later 100 value minus "AcDb" prefix
      (cond
        ((= S2 "3dPolyline") (prompt "\n3DPOLY ") (command "_.3dpoly"))
        ((= S2 "2dPolyline")
          (initget "Heavy Lightweight")
          (if
            (=
              (getkword
                "\nMatch heavy 2D type (other than for Rectangle/Cloud), or use Lightweight type? [H/L] <L>: "
              )
              "Heavy"
            ); =
            (progn; then - old-style "heavy" 2D type
              (setvar 'plinetype 0)
              (alert "Recommend resetting the PLINETYPE System\nVariable to 1 or 2 when finished.")
                ; but doesn't save it and reset it, in case User needs to make more than one of them
            ); progn
            (if (= (getvar 'plinetype) 0) (setvar 'plinetype 2)); else
              ; in case it was set at 0 [old-style "heavy" 2D type]; keep value if 1 [new ones still lightweight];
              ; assumes no desire to return it to 0 - add that resetting/option/recommendation, if desired
          ); if
          (setq S1 "PLine"); to offer as default in (*poly)
          (*poly); subroutine shared with LWPolyline type
        ); second condition - 2D Polyline type
        ((= S2 "PolygonMesh"); [couldn't find a way to differentiate types from entity data]
          (initget "3D 3DMesh Pface REvsurf RUlesurf Tabsurf")
          (setq S2 (getkword
            "\nPolygon Mesh command [3D/3DMesh/Pface/REvsurf/RUlesurf/Tabsurf] <3D>: "))
          (if (member S2 '(nil "3D")); user hit Enter or typed 3D
            (progn (load "3D") (C:3d)); then [loads in case not used before]
            (progn
              (*pcn)
              (command (strcat "_." S2)); else - other entered option
            ); progn
          ); if
        ); third condition - mesh types
      ); cond - variety of Polyline
    ); 3D/heavy 2D Polyline object type
;
  ); cond - OVERARCHING TEST for each object type
;
); defun - C:polylinedxf
(prompt "\nType polylinedxf to Make More the same as an existing object.")
; MakeMore.lsp
 
----------------------------------------------
 
(defun c:rectangledxf ()
 
(setq ss4(ssget "_X" '((0 . "LWPOLYLINE")))
);end setq
 
(setq ss3(ssget "_X" '((0 . "CIRCLE")(-4 . "<=")(40 . 2.0)))
);end setq
 
(command "._change" ss4 "" "p" "LA" "ProcPart_31" "")
(command "._change" ss3 "" "p" "LA" "V_DrillFF_3" "")
(command "_.scale" "all" "" "0,0" "25.4")
 
     (if (and (setq d (abs 3))
      (setq d (/ d 2.))
      (setq ss (ssget "_X" '((8 . "V_DrillFF_3"))))
      )
       (repeat (setq i (sslength ss))
         (setpropertyvalue (ssname ss (setq i (1- i))) "Radius" d)))
 
(command "._zoom" "e")
 
);end rectangledxf
 
-------------------------------------------------
 
(defun c:polylinedxf-step2 ()
 
(vlax-for layout (vla-get-layouts(vla-get-ActiveDocument (vlax-get-acad-object)))
(if (/= (vla-get-name layout) "Model")(vla-delete layout)))
 
(setq ss5(ssget "_X" '((0 . "LWPOLYLINE")))
);end setq
 
(setq ss3(ssget "_X" '((0 . "CIRCLE")(-4 . "<=")(40 . 2.0)))
);end setq
 
(command "._change" ss5 "" "p" "LA" "Geometry_0" "")
(command "._change" ss3 "" "p" "LA" "V_DrillFF_3" "")
(command "_.scale" "all" "" "0,0" "25.4")
 
     (if (and (setq d (abs 3))
      (setq d (/ d 2.))
      (setq ss (ssget "_X" '((8 . "V_DrillFF_3"))))
      )
       (repeat (setq i (sslength ss))
         (setpropertyvalue (ssname ss (setq i (1- i))) "Radius" d)))
 
  (defun obb (ent); = Object's Bounding Box corners
    (vla-getboundingbox (vlax-ename->vla-object ent) 'minpt 'maxpt)
    (setq
      oLL (vlax-safearray->list minpt); Object's Lower Left
      oUR (vlax-safearray->list maxpt); Object's Upper Right
    ); setq
  ); defun -- obb
  (vl-load-com)
  ;;(prompt "\nTo draw the Smallest Rectangle around them,")
  (setq ss (ssget "_X" '((8 . "Geometry_0"))))
  (obb (ssname ss 0))
  (setq LL oLL UR oUR); initial overall LL & UR [of first object]
  (ssdel (ssname ss 0) ss)
  (repeat (sslength ss)
    (obb (ssname ss 0))
    (setq
      LL (mapcar 'min oLL LL); least of each component
      UR (mapcar 'max oUR UR); greatest of each component
    ); setq
    (ssdel (ssname ss 0) ss)
  ); repeat
  (command "_.rectangle" "_none" LL "_none" UR)
  (princ)
 
(setq ss2(ssget "_L")
);end setq
(command "._change" ss2 "" "p" "LA" "ProcPart_31" "")
 
(command "._zoom" "e")
 
);end polylinedxf-step2
 
-----------------------------
 
 

 

0 Likes