Author Topic: Basic DXF code question  (Read 6584 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Basic DXF code question
« Reply #15 on: October 22, 2010, 12:07:28 AM »
Well the short cut is to use commands in the lisp.
That can be done quickly.
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.

KOWBOI

  • Guest
Re: Basic DXF code question
« Reply #16 on: October 22, 2010, 09:54:52 AM »
I was able to take a few minutes and play with the code, this is what I have so far.

Code: [Select]
(defun c:test( / ss)
  (if (setq ss (ssget '((0 . "LWPOLYLINE") (6 . "SOLID") (8 . "COUNTERTOP")))) ; from Lee
    (progn
      (command "change" ss "" "p"
               "LT" "ByLayer"
               "C" "ByLayer"
               "LA" "OBJECT" ""
               "EXPLODE" SS
              )
    )
  )
  (princ)
)

How do I incorporate the following into the selection set?

Code: [Select]
(0 . "TEXT") (7 . "Standard") (8 . "COUNTERTOP")

(0 . "POINT") (8 . "PNTS")

Lee Mac

  • Seagull
  • Posts: 12923
  • London, England
Re: Basic DXF code question
« Reply #17 on: October 22, 2010, 10:02:15 AM »
Perhaps something like:

Code: [Select]
(defun c:test ( / ss )
 
  (if (setq ss
        (ssget "_:L"
         '(
            (-4 . "<OR")
              (-4 . "<AND")
                (0 . "LWPOLYLINE")
                (6 . "SOLID")
                (8 . "COUNTERTOP")
              (-4 . "AND>")
              (-4 . "<AND")
                (0 . "TEXT")
                (7 . "Standard")
                (8 . "COUNTERTOP")
              (-4 . "AND>")
              (-4 . "<AND")
                (0 . "POINT")
                (8 . "PNTS")
              (-4 . "AND>")
            (-4 . "OR>")
          )
        )
      )

    ;; No need for progn, only have one expression:

    (command "change" ss "" "p"
               "LT" "ByLayer"
               "C" "ByLayer"
               "LA" "OBJECT" ""
               "EXPLODE" SS
    )
  )
 
  (princ)
)

KOWBOI

  • Guest
Re: Basic DXF code question
« Reply #18 on: October 22, 2010, 11:04:43 AM »
Thanks Lee, that works perfectly. Could you explain the process of what you did so I don't just plug code in without understanding it? My next step is to scale and rotate the selection set.

Lee Mac

  • Seagull
  • Posts: 12923
  • London, England
Re: Basic DXF code question
« Reply #19 on: October 22, 2010, 11:10:49 AM »
Have a read of the VLIDE Help docs on:

Code: [Select]
Using the AutoLISP Language > Using AutoLISP to Manipulate AutoCAD Objects > Selection Set Handling > Selection Set Filter Lists > Logical Grouping of Filter Tests
Also:

Code: [Select]
Using the AutoLISP Language > Using AutoLISP to Manipulate AutoCAD Objects > Selection Set Handling > Selection Set Filter Lists > Relational Tests

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Basic DXF code question
« Reply #20 on: October 22, 2010, 11:51:16 AM »
You can convert the command line sequence into code but you have to have a way to create the input
or user responses needed for each command.
Here is the code with the additional commands added.
Your job is to figure out how to replace the pause which is waiting for user responses with a
code solution for these responses.

Code: [Select]
(defun c:test (/ ss i ename flag)
  (if (setq ss
             (ssget "_:L"
                    '(
            (-4 . "<OR")
              (-4 . "<AND")
                (0 . "LWPOLYLINE")
                (6 . "SOLID")
                (8 . "COUNTERTOP")
              (-4 . "AND>")
              (-4 . "<AND")
                (0 . "TEXT")
                (7 . "Standard")
                (8 . "COUNTERTOP")
              (-4 . "AND>")
              (-4 . "<AND")
                (0 . "POINT")
                (8 . "PNTS")
              (-4 . "AND>")
            (-4 . "OR>")
                     )
             )
      )
    (progn
      (command "change" ss "" "p" "LT" "ByLayer" "C" "ByLayer" "LA" "OBJECT" "")
      (command "scale" ss "" pause ; need base point for scale
               1.5)
      (command "Rotate" ss "" pause ; need base point for rotate
               "R" pause ; need the reference angle
               pause ; need the new angle
               )
       (setq i 0)
       (while (setq ename (ssname ss i))
         (if (equal (assoc 0 (entget ename)) '(0 . "LWPOLYLINE"))
           (setq i (1+ i))
           (ssdel ename ss)
         )
       )
      (if (and ss (/= 0 (sslength ss)))
        (progn
          (setq flag (getvar "qaflags"))
          (setvar "qaflags" 5)
          (command "explode" ss "")
          (setvar "qaflags" flag)
        )
      )
    )
  )
  (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.