Author Topic: CAD Setup Routine  (Read 64400 times)

0 Members and 1 Guest are viewing this topic.

amgirard2003

  • Guest
CAD Setup Routine
« Reply #195 on: February 05, 2004, 01:59:11 PM »
Do you want the full list or partial list?
I have close to 200 here..

daron

  • Guest
CAD Setup Routine
« Reply #196 on: February 05, 2004, 02:02:56 PM »
Why don't you give me 10 and I'll see what I can do with them.

amgirard2003

  • Guest
CAD Setup Routine
« Reply #197 on: February 05, 2004, 02:08:32 PM »
layer, color , linetype

610 , magenta, continuous
612 , magenta, hidden
622 , yellow , hidden
626 , green, continuous
410 , 8 , conitnuous
198 , 7 , continuous
102 , cyan , continous
49 , 50, continous
60 , 70 , continous
64, 7, continous

all of these layers are ON, Thawed, Unlocked, lineweight is default (we use ctb files when plotting) and all plot..

amgirard2003

  • Guest
CAD Setup Routine
« Reply #198 on: February 05, 2004, 02:17:46 PM »
my head is sore trying to figure out this pedit thingy...
don't know where to begin...

daron

  • Guest
CAD Setup Routine
« Reply #199 on: February 05, 2004, 04:17:17 PM »
Keep the pedit thing in the back of your mind, but focus on this a moment:
Code: [Select]

;;;creates a nested list of layernames, colors and linetypes
;;;return value: three lists of multiple items
(defun multi-list-layers ()
     (list
 (list "610" "612" "622" "626" "410" "198" "102" "49" "60" "64")
 ;;layername list
 (list 6 6 2 3 8 7 4 50 70 7)
 ;;layer color list
 (list "continuous" "hidden"  "hidden"
"continuous" "conitnuous"  "continuous"
"continous" "continous"  "continous"
"continous"
      )
 ;;layer linetypes list
     )
)
;;;creates a nested list of layers with properties in each container
;;;return value: ex. ("610" 6 "continuous)
(defun multi-layer-list ()
     (list
 (list "610" 6 "continuous") ;name color linetype
 (list "612" 6 "hidden")
 (list "622" 2 "hidden")
 (list "626" 3 "continuous")
 (list "410" 8 "continuous")
 (list "198" 7 "continuous")
 (list "102" 4 "continuous")
 (list "49" 50 "continuous")
 (list "60" 70 "continuous")
 (list "64" 7 "continuous")
     )
)

There's two ways here to set up a list. The first one creates a list for each type of property i.e. a list of layer names, a list of colors and a list of linetypes. You will only ever have three lists in that list, but on the whole it can get confusing if you need to update anything or add to it. The second function will create a list of lists each containing three properties. This way is much easier to digest, and update. I'm showing both because the first way was the idea in my head. So, it in a sense is my pseudo-code. You will probably agree that the second one makes more sense, as do I. Both will work, though. What do you think as this being a way to set up your layers? Of course, it's only a set of lists at this point and won't do anything but return a set of lists. It's a work in progress. Take it, test it, add the rest of your layers to it. Tell me what you think. The next step is either creating a function to process each list to creating each layer and its respective property or taking one of the many layer creation tools that are on this site and modifying it to suit.

amgirard2003

  • Guest
CAD Setup Routine
« Reply #200 on: February 09, 2004, 07:33:35 AM »
Thanks Daron for your help..
I'll create a list with all the layers that i have and i will let you know when i'm done..
I'm back with a clearer mind and ready to learn some new things..

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
CAD Setup Routine
« Reply #201 on: February 09, 2004, 08:38:40 AM »
Quote from: amgirard2003
I've learned a lot about all the function and how they work individually, but when trying to put them together to function as a group.. i just throw my arm's in the air and just wanna yell!!!..
And that's when i start to get frustrated...


You have learned several words (functions) very well and you have a
vague idea of the meaning of quite a few more. But you feel frustrated
you can't speak the language fluently. Well, you have come a long
way in a short time (thanks to Daron and others). I can only speak for
myself but it appears you are close to the point where you can put short
phrases together and soon after that sentences. And only then can you carry
on a conversation. After one year I am starting to feel comfortable with lisp
and in looking back at previous conversations (routines) I misused some of
the words, poor grammar etc, but I was able to converse. Keep it up and the folks
here will help you along your journey. Mostly gently, sometime not, but always
with good intention. :)

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.

SMadsen

  • Guest
CAD Setup Routine
« Reply #202 on: February 09, 2004, 08:44:34 AM »
To make it easier on yourself when creating the layer list, you can decide to make it possible to omit some of the information. For example, if omitting color number and/or linetype name, you can assign default values when creating the layers.

The syntax for each layer item could be
(layername [color [ltype]]),
where layername is obligatory, while color and linetype can be omitted. Omitting color cannot be done without also omitting linetype.

Anyway, some code should make this clearer:
Code: [Select]
(defun multi-layer-list ()
  ;; format: name color linetype
  (list
    '("610" 6)
    '("612" 6 "hidden")
    '("622" 2 "hidden")
    '("626" 3)
    '("410" 8)
    '("198")
    '("102" "hidden")
    '("49" 50)
    '("60" 70)
    '("64"))
)

(defun makeLayers (/ failed layerlist name color ltype)
  (setq failed 0)
  (cond
    ;; get pre-formatted list of layers
    ((setq layerlist (multi-layer-list))
     ;; Run through each item in layerlist, assign
     ;; name, color and linetype. If any item is
     ;; missing, we'll deal with it at the time of
     ;; layer creation
     (foreach layer layerlist
       (setq name  (car layer)
             color (cadr layer)
             ltype (caddr layer)
       )
       ;; Do the actual creation of layers. If color and/or
       ;; linetype is missing, then assign some default values.
       (if (not (entmake
             (list '(0 . "LAYER")
                   '(100 . "AcDbSymbolTableRecord")
                   '(100 . "AcDbLayerTableRecord")
                   ;; Insert layer name
                   (cons 2 name)
                   ;; Insert color by layerlist or default of 7 if missing
                   (cond ((= (type color) 'INT) (cons 62 color))
                         ((cons 62 7))
                   )
                   ;; Insert ltype if found in linetype table.
                   ;; If not found or missing in layerlist then
                   ;; insert default linetype, i.e. "Continuous"
                   (cond
                     ((and (= (type ltype) 'STR) (tblsearch "LTYPE" ltype))
                     (cons 6 ltype))
                     ((cons 6 "Continuous"))
                   )
                   '(70 . 0)
             )
           )
         )
         ;; If layer creation failed then increment counter
         (setq failed (1+ failed))
       )
     )
     ;; If some layer creations failed then report it. Notice that
     ;; failing to create a layer can also be caused by the fact that
     ;; the layer already exists
     (if (not (zerop failed))
       (princ (strcat "\nFailed to make " (itoa failed) " layers"))
     )
    )
  )
  (princ)
)

daron

  • Guest
CAD Setup Routine
« Reply #203 on: February 09, 2004, 09:43:49 AM »
Andre' I couldn't imagine a better, faster way of doing what Stig just did. Thanks, Stig. The challenge, Andre' is to take out all the comments, so you have just code and step through each line. Better yet, so you can step through each line, I've altered Stig's makelayer function from using foreach and made it repeat. The challenge here is to step through the repeat version and see what makes it tick, then go back to the foreach version and try to understand it. The best way to understand a foreach function that I've found is, under debug, select animate and just watch what is going to happen as the vlide steps through the function. Do this only when you have some spare time. It can be a slow arduous process. Don't do it on more than 3 or 4 layers. Here's the repeat version:
Code: [Select]
(defun makeLayers (/ failed layerlist name color ltype)
  (setq failed 0
cnt 0)
  (cond
    ((setq layerlist (multi-layer-list))
     (repeat (length layerlist)
       (setq name  (car (nth cnt layerlist))
             color (cadr (nth cnt layerlist))
             ltype (caddr (nth cnt layerlist))
       )
       (if (not (entmake
             (list '(0 . "LAYER")
                   '(100 . "AcDbSymbolTableRecord")
                   '(100 . "AcDbLayerTableRecord")
                   (cons 2 name)
                   (cond ((= (type color) 'INT) (cons 62 color))
                         ((cons 62 7))
                   )
                   (cond
                     ((and (= (type ltype) 'STR) (tblsearch "LTYPE" ltype))
                     (cons 6 ltype))
                     ((cons 6 "Continuous"))
                   )
                   '(70 . 0)
             )
           )
         )
         (setq failed (1+ failed))
       )
 (setq cnt (1+ cnt))
     )
     (if (not (zerop failed))
       (princ (strcat "\nFailed to make " (itoa failed) " layers"))
     )
    )
  )
  (princ)
)

amgirard2003

  • Guest
CAD Setup Routine
« Reply #204 on: February 09, 2004, 10:11:31 AM »
Quote from: CAB

You have learned several words (functions) very well and you have a
vague idea of the meaning of quite a few more. But you feel frustrated
you can't speak the language fluently. Well, you have come a long
way in a short time (thanks to Daron and others). I can only speak for
myself but it appears you are close to the point where you can put short
phrases together and soon after that sentences. And only then can you carry
on a conversation. After one year I am starting to feel comfortable with lisp
and in looking back at previous conversations (routines) I misused some of
the words, poor grammar etc, but I was able to converse. Keep it up and the folks
here will help you along your journey. Mostly gently, sometime not, but always
with good intention. :)

CAB


CAB- you hit the nail on head.... that is exactly how i feel.... i understand how the functions work (WORDS) but putting the (WORDS) together to make a clear sentence (ROUTINE) is where i get lost...

I know it will take time before i'll be able to make comprehendible sentences, but i will be patient and take my time to learn all that i can.

amgirard2003

  • Guest
CAD Setup Routine
« Reply #205 on: February 09, 2004, 11:54:21 AM »
I've been playing around with the 2 routines and i feel i understand them pretty well... I'm still tryin to understand what you guys think about when you're putting the routine together...
Overall i understand both pretty well... I can see what they are doing and what all the functions are doing as well.. :D

That would take care of both the creations and re-loading of the layers.

daron

  • Guest
CAD Setup Routine
« Reply #206 on: February 09, 2004, 12:06:17 PM »
Here's something I didn't write. It was here, when I got here. I don't even like to look at it, but it should help you with the pljoin function.
Code: [Select]
(defun c:plj (/ ss i en et osm snm) ; STAND-ALONE FUNCTION.
     (setq osm (getvar "OSMODE")
  snm (getvar "SNAPMODE")
     ) ; SAVE MODES.
     (setvar "CMDECHO" 0)
     (setvar "OSMODE" 0)
     (setvar "SNAPMODE" 0)
     (prompt
 "  PLineJoin... Select the Lines, Arcs, and Plines to Join:"
     ) ;_ end of prompt
     (if (setq ss (ssget))
 (progn

 ; MUST REMOVE CLOSED, FITCURVED, & SPLINED PLINES FROM SELECTION SET.
      (prompt "Initial scan")
      (setq i (1- (sslength ss)))
      (while (>= i 0)
   (setq et  (cdr (assoc 0
 (entget (setq en (ssname ss i)))
  ) ;_ end of assoc
     ) ;_ end of cdr
   ) ;_ end of setq
   (cond ((or (= et "LINE") (= et "ARC")))
 ((= et "LWPOLYLINE")
  (if (> (cdr (assoc 70 (entget en))) 0)
 ; IF>0, PLINE FLAGS SET.
(ssdel en ss)
  ) ;_ end of if
 ) ; END IF & "POLYLINE".
 (t (ssdel en ss)) ; END T
   ) ; END COND
   (prompt ".")
   (setq i (1- i))
      ) ; END WHILE
 ; END MUST REMOVE.

      (setq i (1- (sslength ss)))
      (while (>= i 0)
   (setq et  (cdr (assoc 0
 (entget (setq en (ssname ss i)))
  ) ;_ end of assoc
     ) ;_ end of cdr
   ) ;_ end of setq
   (cond ((= et "LWPOLYLINE")
  (command ".PEDIT" en "J" ss "" "X")
 )
 ((= et "LINE")
  (command ".PEDIT" en "Y" "J" ss "" "x")
 )
 ((= et "ARC")
  (command ".PEDIT" en "Y" "J" ss "" "x")
 )
   ) ; END COND.
   (setq i (1- i))
   (prompt ".")
      ) ;_ end of while
 ) ;_ end of progn
     ) ; END OF WHILE i<lth, PROGN, IF ss
     (setvar "OSMODE" osm)
     (setvar "SNAPMODE" snm) ; RESTORE MODES.
     (setvar "CMDECHO" 1)
     (setq i "Done joining.")
) ; END FUNC.


Back to the previous two functions. Stig used, in the foreach, (car layer)... I used in the repeat, (car (nth cnt layername)... Why?

amgirard2003

  • Guest
CAD Setup Routine
« Reply #207 on: February 09, 2004, 12:53:39 PM »
Quote from: Daron
Back to the previous two functions. Stig used, in the foreach, (car layer)... I used in the repeat, (car (nth cnt layerlist)... Why?


In the repeat function you used the (car (nth cnt layerlist) because you wanted to return of the first element of the current list it is looking at..

EX:Line 1 (list "610" 6 "continuous")  
     Line 2 (list "612" 6 "hidden")
     Line 3 (list "622" 2 "hidden")
     Line 4 (list "626" 3 "continuous")

car: would return the layer name
nth: is the line of the list (cnt = line 1)

I couldn't figure out how to say it right but i hope you'll get what i'm tryin to say.

daron

  • Guest
CAD Setup Routine
« Reply #208 on: February 09, 2004, 01:02:02 PM »
Okay, so why doesn't Stig have to do that in the foreach? What's so special about it? What I'm trying to get to, is to see if you know what you have to do to be able to take a line in a foreach code and inspect it. What's the next thing you want to do, after layers?

amgirard2003

  • Guest
CAD Setup Routine
« Reply #209 on: February 09, 2004, 01:16:09 PM »
In stig's routine FOREACH works exactly like the nth function..it's like built into the foreach function.
You specify what part of the list you want to return and it will go through
each line of the list and return that part.