+ Reply to Thread
Page 3 of 4 FirstFirst 1 2 3 4 LastLast
Results 21 to 30 of 40
  1. #21
    Full Member
    Discipline
    Electrical
    btraemoore's Discipline Details
    Occupation
    Electrical Designer
    Discipline
    Electrical
    Using
    Electrical 2012
    Join Date
    Apr 2012
    Location
    Houston
    Posts
    55

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by pBe View Post
    Yup, sort of... i can write a snippet for you.... you didnt answer my question though,
    in the drawing there wouldn't be 2 layers with identical names, if there is ELECTRICAL/1/HIDDEN it will be renamed to elec and then move to the next layer in question.. here is the coding that i have so far

    Code:
    (vl-load-com)
    	(setq acadDocument (vla-get-activedocument (vlax-get-acad-object)))
    	(setq layertable (vla-get-layers acadDocument))
    		(while (setq Lay (tblnext "LAYER" 1))
    			(setq layLT (cdr (assoc 6 lay)) 
    				  layCOLOR (itoa (cdr (assoc 62 lay)))
    				  layNM (cdr (assoc 2 lay))
    				  claylst (list laycolor laylt)
    			);setq
    				(setq f (open "C:/Documents and Settings/moorerb/Desktop/scripting-lisp/standardlayers.txt" "r"))
    				(while (/= dataline1 "eof")
    					(setq dataline1 (read-line f))
    					(setq k 1)
    					(setq a "")
    					(setq lst nil)
    					(setq laylst nil)
    					(repeat (strlen dataline1)
    							(if (= (substr dataline1 k 1) "\t")
    								(progn
    									(setq lst (append lst (list a)))
    									(setq a "")
    								);progn
    								(setq a (strcat a (substr dataline1 k 1)))
    							);if
    							(setq k (+ k 1))
    					);repeat
    					(setq lst (append lst (list a)))
    					(setq lstlaynm (car (cdr (cons 1 lst))))
    						(if (/= lstlaynm laynm)
    							(setq clst (cdr (cdr (cons 1 lst))))
    							(if (and (= (nth 1 clst)(nth 1 claylst))(= (nth 2 clst)(nth 2 claylst)))

  2. #22
    Forum Deity pBe's Avatar
    Computer Details
    pBe's Computer Details
    Operating System:
    Windows XP
    Discipline
    Construction
    pBe's Discipline Details
    Discipline
    Construction
    Details
    Camp Construction planning and details
    Using
    AutoCAD 2009
    Join Date
    Apr 2010
    Posts
    2,089

    Default

    btraemoore.
    First of all, dont put the read-line function inside the while loop.Read and parse the text file once to create a list

    Where laylst is the data from reading and parsing the file
    Lets say you have the layer ELECTRICAL 7 HIDDEN
    <untested>
    Code:
    (defun c:moore (/ _match laylst a coll tlst)
    (defun _match  (nm col lt lst / n f)
        (while (and (setq n (car lst)) (not f))
              (if (and
                        (wcmatch (strcase nm) (strcat (car n) "*"))
                        (eq col (cadr n))
                        (eq (strcase lt) (last n)))
                    (setq f T)
                    (setq lst (cdr lst)))) (car n))
    (vl-load-com)
    (setq acadDocument (vla-get-activedocument (vlax-get-acad-object)))
    (setq layertable (vla-get-layers acadDocument))
    ;;; example Result from a parsing routine  ;;;
    (setq laylst '(("CPRT" 4 "CONTINUOUS") ("CPRT" 7 "CONTINUOUS")
              ("CUTLINE" 5 "HIDDEN") ("CUTLINE" 7 "HIDDEN")
              ("DASHED" 2 "DASHED") ("DASHED" 2 "PHANTOM")
              ("DASHED" 7 "PHANTOM") ("DEFPOINTS" 7 "CONTINUOUS")
              ("DEPT" 3 "CONTINUOUS")  ("DEPT" 7 "CONTINUOUS")
              ("DIM" 2 "CONTINUOUS") ("DIM" 7 "CONTINUOUS")
              ("DIMN" 1 "CONTINUOUS") ("DIMN" 7 "CONTINUOUS")
              ("ELEC" 1 "HIDDEN") ("ELEC" 7 "HIDDEN")))                
    (while (setq a (tblnext "LAYER" (null a)))
            (setq coll (list (cdr (assoc 2 a))
                                     (cdr (assoc 62 a))
                                     (cdr (assoc 6 a))))
      (if (and (setq tlst (vl-remove-if-not  '(lambda (ly)
                                  (eq (strcase (substr (car ly) 1 1))
                                      (strcase (substr (car coll) 1 1)))) laylst))
                (setq newname (_match (car coll)(cadr coll)(last coll) tlst))
                             )
             (vla-put-name (vla-item layertable (car coll)) newname))
          )
          )
    It reduces the list per loop depending on the first character of the layername
    Then use _match routine for "comparison" test if found returens the New Layer Name

    HTH

    BTW: what i meant by this

    ELECTRICAL/1/HIDDEN will be ELEC, and ELECTRICAL/7/HIDDEN will also be ELEC, is that right?
    is it one or the other? because you have two lines ELEC 1 HIDDEN ELEC 7 HIDDEN included on the text file.

  3. #23
    Full Member
    Discipline
    Electrical
    btraemoore's Discipline Details
    Occupation
    Electrical Designer
    Discipline
    Electrical
    Using
    Electrical 2012
    Join Date
    Apr 2012
    Location
    Houston
    Posts
    55

    Default

    im having a hard time understanding what you did with the _match, after did you basically compare everything at the same time?

  4. #24
    Full Member
    Discipline
    Electrical
    btraemoore's Discipline Details
    Occupation
    Electrical Designer
    Discipline
    Electrical
    Using
    Electrical 2012
    Join Date
    Apr 2012
    Location
    Houston
    Posts
    55

    Default

    This is where I'm at so far, now i am going to try to use the wcmatch to narrow down my name selection
    Code:
    (defun fixlay (/)
    	(vl-load-com)
    	(setq acadDocument (vla-get-activedocument (vlax-get-acad-object)))
    	(setq layertable (vla-get-layers acadDocument))
    		(setq f (open "C:/Documents and Settings/moorerb/Desktop/scripting-lisp/standardlayers.txt" "r"))
    		(while (setq Lay (tblnext "LAYER" 1))
    			(setq oldlayLT (cdr (assoc 6 lay)) 
    				oldlayCOLOR (itoa (cdr (assoc 62 lay)))
    				oldlayNM (cdr (assoc 2 lay))
    				oldcompLST (list laycolor laylt))
    			(while (/= dataline1 "eof")
    				(setq dataline (read-line f)
    					k 1
    					a ""
    					LST nil)	
    				(repeat (strlen dataline1)
    					(if (= (substr dataline k 1) "\t")
    						(progn
    							(setq LST (append LST (list a)))
    							(setq a "")
    						);progn
    						(setq a (strcat a (substr dataline k 1)))
    					);if
    					(setq k (+ k 1))
    				);repeat
    			(setq LST (append LST (list a)))
    			(setq newlayNM (car (cdr (cons 1 LST)))
    				newcompLST (cdr (cdr (cons 1 LST)))
    				newlayLT (cdr (cdr LST))
    				newlayCOLOR (atoi (car (cdr lst))))
    				(if (/= newlayNM oldlayNM)
    					(progn
    						(if (and (= (nth 1 oldcompLST)(nth 1 newcompLST))(= (nth 2 oldcompLST)(nth 2 newcompLST)))
    							(setq newlayNMLST (append newlayNMLST (list newlayNM)))
    						);if
    					);progn
    						(if (/= oldlayLT newlayLT)
    							(vlax-put-property LAY 'Linetype newlayLT));if
    						(if (/= oldlayCOLOR newlayCOLOR)
    							(vlax-put-property LAY 'Color newlayCOLOR)
    						);if
    				);if
    			);while
    			
    		);while

  5. #25
    Forum Deity pBe's Avatar
    Computer Details
    pBe's Computer Details
    Operating System:
    Windows XP
    Discipline
    Construction
    pBe's Discipline Details
    Discipline
    Construction
    Details
    Camp Construction planning and details
    Using
    AutoCAD 2009
    Join Date
    Apr 2010
    Posts
    2,089

    Default

    The second line is the new Nane, Linetype and Color. So its not jsut the name but also the lt and color

    CLINE 7 CENTER <--for comparison
    CLINES 7 CENTER2 <-- if found assign new Name, color, Linetype

    Load layers (revert to original state) and Transalte (This name to that) at the same time. I've seen a lot Layer routine out there, but this one takes the cake
    I can modify the code i posted to do just that. I'll look into it later.

  6. #26
    Full Member
    Discipline
    Electrical
    btraemoore's Discipline Details
    Occupation
    Electrical Designer
    Discipline
    Electrical
    Using
    Electrical 2012
    Join Date
    Apr 2012
    Location
    Houston
    Posts
    55

    Default

    hey, good morning. alright, so i tried to read the code this morning and i cant seem to understand what it is doing. I mean i get that it fixes it, but i guess i dont understand the coding for the _match, if you could comment it out for me so i can learn from it that would be awesome



    edit: its very important that i learn from it, especially when i have no one to teach me. Im only about a month in to coding...

  7. #27
    Forum Deity pBe's Avatar
    Computer Details
    pBe's Computer Details
    Operating System:
    Windows XP
    Discipline
    Construction
    pBe's Discipline Details
    Discipline
    Construction
    Details
    Camp Construction planning and details
    Using
    AutoCAD 2009
    Join Date
    Apr 2010
    Posts
    2,089

    Default

    Good for you btraemoore. Should we proceed with that approach? If YES, i still need to modify _Match sub-routine Would you like maintain the sequence the way your code is written? Am i correct in my assumption on the previous post?

    CLINE 7 CENTER <--for comparison CLINES 7 CENTER2 <-- if found assign new Name, color, Linetype
    Would you want to replace your code the way the file is read and stored on a list?

    On another note. Hang around and read the posts on this forum, You'll be amaze how one task can be coded in so many different ways. On my part i'm still a novice and still have much to learn.

  8. #28
    Full Member
    Discipline
    Electrical
    btraemoore's Discipline Details
    Occupation
    Electrical Designer
    Discipline
    Electrical
    Using
    Electrical 2012
    Join Date
    Apr 2012
    Location
    Houston
    Posts
    55

    Default

    Quote Originally Posted by pBe View Post
    CLINE 7 CENTER <--for comparison CLINES 7 CENTER2 <-- if found assign new Name, color, Linetype[/I]
    yes this is ultimately what i am trying to do, i guess i prefer the syntax the way i write because its easier for me to read and to learn from. I am still playing around with the code that i wrote... soooo many bugs i keep getting a stringp nil error... im guessing its because its not moving to the next layer in the table... visual lisp is extremely new for me, but yes you have the right idea of what i want to do with this routine. Thank you very much for your help

  9. #29
    Full Member
    Discipline
    Electrical
    btraemoore's Discipline Details
    Occupation
    Electrical Designer
    Discipline
    Electrical
    Using
    Electrical 2012
    Join Date
    Apr 2012
    Location
    Houston
    Posts
    55

    Default

    so, this is where i am at. I'm not getting any errors, but its not reading past the first layer


    Code:
    (defun C:flay ()
    	(vl-load-com)
    	(setq acadDocument (vla-get-activedocument (vlax-get-acad-object)))
    	(setq layertable (vla-get-layers acadDocument))
    	(setq f (open "C:/Documents and Settings/moorerb/Desktop/scripting-lisp/standardlayers.txt" "r"))
    	(setq Lay (tblnext "LAYER" 1))
    	(setq count 0)
    	(setq mcnt 0)
    	(repeat laycnt
    		(setq oldlayLT (cdr (assoc 6 lay)) 
    			oldlayCOLOR (itoa (cdr (assoc 62 lay)))
    			oldlayNM (cdr (assoc 2 lay))
    			oldcompLST (list oldlayCOLOR oldlayLT)
    			dataline (read-line f))
    		(while (/= dataline nil) 
    			(setq k 1
    				a ""
    				LST nil)	
    			(repeat (strlen dataline)
    				(if (= (substr dataline k 1) "\t")
    					(progn
    						(setq LST (append LST (list a)))
    						(setq a "")
    					)
    					(setq a (strcat a (substr dataline k 1)))
    				)
    				(setq k (+ k 1))
    			)
    		(setq LST (append LST (list a)))
    		(setq mlst (append mlst (list lst)))
    		(setq newlayNM (car (cdr (cons 1 LST)))
    			newcompLST (cdr (cdr (cons 1 LST)))
    			newlayLT (cdr (cdr LST))
    			newlayCOLOR (car (cdr lst))) 
    			(if (= newlaynm oldlaynm)
    				(progn 
    				(setq count (+ 1 count))
    					(if (and (= oldlaycolor newlaycolor)(= oldlaylt newlaylt))
    						(progn
    							(setq newlayNMLST (append newlayNMLST (list newlayNM)))
    						)
    					)
    				)
    				(setq match (append match (list oldlaynm)) mcnt (+ mcnt 1));;; just a test	
    			)
    			(princ oldlaynm)(princ " ");;;another test
    			(setq dataline (read-line f))
    		)
    		
    		
    	)(setq Lay (tblnext "LAYER"))
    )
    
    
    
    (defun c:Lcnt()
    	(setq acadDocument (vla-get-activedocument (vlax-get-acad-object)))
    	(setq layertable (vla-get-layers acadDocument))
    	(setq Lay (tblnext "LAYER" 1))
    	(while lay
    		(setq oldlayNM (cdr (assoc 2 lay)))
    		(setq laycnt (append laycnt (list oldlaynm)))
    		(setq lay (tblnext "layer"))
    	)
    	(setq laycnt (length laycnt))
    )
    
    (defun c:fixlay(/ laycnt)
    (command "-purge" "a" "" "n")
    (c:lcnt)
    (c:flay)
    );defun

    this is what i get in my command box after running the routine.
    Command: 0 BORDER ELEC MATCH POWER SYMBOLS TEXT UTIL BALLOON nil

    Command: !match
    ("0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0"
    "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0"
    "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0"
    "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0"
    "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0"
    "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0"
    "0" "0" "0" "0" "0" "0" "0" "0")
    any suggestions?

  10. #30
    Forum Deity pBe's Avatar
    Computer Details
    pBe's Computer Details
    Operating System:
    Windows XP
    Discipline
    Construction
    pBe's Discipline Details
    Discipline
    Construction
    Details
    Camp Construction planning and details
    Using
    AutoCAD 2009
    Join Date
    Apr 2010
    Posts
    2,089

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by btraemoore View Post
    so, this is where i am at. I'm not getting any errors, but its not reading past the first layer
    any suggestions?

    (= newlaynm oldlaynm) evaluates to nil as variable LAY remains as "0" thru the entire repeat/loop [Hence you get this -> ("0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" ....)] because you had this (setq Lay (tblnext "LAYER")) outside repeat. I wouldsuggest you use (wcmatch oldlaynm (strcat newlaynm "*"))

    Anyhoo, thats sut one of the "bugs" btraemoore.
    For now have a look-see at this code
    Code:
    (defun c:moore (/ _match _delFinder _entmod laylst
                      f a laylst coll  newname Thislayer)
    (vl-load-com)
    (defun _match  (nm col lt lst / n fn)
        (while (and (setq n (car lst)) (not fn))
              (if (and
                        (wcmatch (strcase nm) (strcat (car n) "*"))
                        (= col (atoi (cadr n)))
                        (eq (strcase lt) (last n)))
                    (setq fn  (cadr lst))
                    (setq lst (cddr lst)))) fn)
    (defun _delFinder  (str md / d l str)
          (while (setq d (vl-string-position md str nil T))
                (setq l (cons (substr str (+ 2 d)) l)
                      str (substr str 1 d)))
          (cons str l)
          )
    (setq _entmod (lambda (v dx entg)
     (entmod (subst (cons dx v)(assoc dx entg) entg))))     
    (if (setq laylst nil
                 f (findfile "C:/Documents and Settings/moorerb/Desktop/scripting-lisp/standardlayers.txt"))
           (progn
              (setq f (open f "r"))
               (while (setq a (read-line f))
            (setq laylst (cons (_delFinder a 32) laylst))   
                      )
              (setq laylst (reverse laylst))
              (close f) 
     (while (setq a (tblnext "LAYER" (null a)))
       (cond ((and
               (not (member (setq lyn  (cdr (assoc 2 a))) '("DEFPOINTS" "0")))
                    (setq coll (list lyn (cdr (assoc 62 a))(cdr (assoc 6 a))))
      (setq newname (_match lyn (cadr coll)(last coll) laylst))
      (setq Thislayer (entget (tblobjname "LAYER" lyn))
            Thislayer (if (not (tblsearch "LAYER" (car newname)))
                                        (_entmod (car newname) 2 Thislayer)
                                        Thislayer)
                   Thislayer (_entmod (atoi (cadr newname)) 62 Thislayer)
                   Thislayer (_entmod (caddr newname) 6 Thislayer))
                    )))
                  )
              )
          )(princ)
     )
    I tried to write it without Vlisp (execpt vl-string-position : run out of time) Also i notice you have "0" include on the list and "2" right after that. You cannot rename layer "0"

    Tell me what part you dont undertstand, then i'll put a comment on those parts.

    HTH

    CODE UPDATED:
    Remove function for reduce list
    Remove m variable
    Allow a totally different name if the 1st lien is a match
    If new layer name exist change the Color and/or Linetype.
    Last edited by pBe; 3rd May 2012 at 11:38 am. Reason: Update Code

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts