Results 1 to 10 of 10

Thread: foreach lay NOT in layerlist

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Member
    Join Date
    2019-05
    Posts
    15
    Login to Give a bone
    0

    Default foreach lay NOT in layerlist

    Is there a simple way to invert the line (foreach lay laylist ?

    I assumed/hoped it would be as simple as writing something like (foreach lay / laylist


    But that didn't work and I can't seem to find the correct way of writing something like that..

    Cheers

  2. #2
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: foreach lay NOT in layerlist

    Perhaps it would help (us help you) if you post what you're actually trying to do?

    (LayoutList) contains all Layouts in a given drawing; you don't need to iterate Model, as it is the only non-Layout tab in same.

    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  3. #3
    Member
    Join Date
    2019-05
    Posts
    15
    Login to Give a bone
    0

    Default Re: foreach lay NOT in layerlist

    Mm.. ok admittedly there are a couple of things wrong with with my code (that i can tell):

    What I'm trying to do is find all the xrefs that are on layers NOT specified in my given list, and create a list of those xrefs (we want to know if xrefs are existing on layers that they're not suppose to be on).

    So I had a feeling I couldn't just say (foreach lay NOT in laylist like i asked initially, & instead I'm now creating a list of ALL layers ("layall"), & subtracting my specified list of layers ("laylist1") to create a list of remaining layers for me to check if xrefs are existing on ("laylist2").

    Code:
    ;; ATTEMPT 2 - Working thorugh reverse layer list and if xrefs then add to list
    
    (defun C:getxref (/ laylist1 layall laylist2 xrlist activedocument theblocks yesxref ablock)
    
    		(setq laylist1 '("XREF-IMG-FRT"  						;establish laylist1	
    						"XREF"
    						"XREF-IMG-BCK"
    						);end_laylist
    		);end_setq
    
    (vlax-for lyr											;establish layall (all layers)
    	(vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
    	(setq layall (cons (vla-get-name lyr) layall))
    )																		
    
    ;(vl-remove pi (list pi t 0 "abc"))
    (setq laylist2 (vl-remove laylist1 (layall)))							;subtract laylist1 from layall to get laylist2		X)faulty
    
    (foreach lay laylist2 													
    	(vl-load-com)
    	(setq activedocument (vla-get-activedocument (vlax-get-Acad-Object)))
    	(setq theblocks (vla-get-blocks activedocument))					;this needs to be get-block from current layer/"lay"         X)faulty
    	(setq xrlist '())													
    	(vlax-for item theblocks
    		(setq yesxref (vlax-get-property item 'isXref))
    
    		(if (= yesxref :vlax-true)							;if the block is xref								
    
    			(progn
    				(setq ablock (vlax-get-property item 'Name))
    				(setq xrlist (append (list ablock) xrlist))			;establish xrlist - list of xrefs on layers belonging to laylist2
    			);progn
    
    		);if
    	);vlax-for
    );foreach
    (princ xrlist)
    );defun
    I've marked the lines which I've identified as not working how I'd like it to.

  4. #4
    Member
    Join Date
    2019-05
    Posts
    15
    Login to Give a bone
    0

    Default Re: foreach lay NOT in layerlist

    I solved the first part!!

    Code:
    ;(vl-remove pi (list pi t 0 "abc"))
    (setq laylist2 (vl-remove laylist1 (layall)))							;subtract laylist1 from layall to get laylist2		X)faulty
    becomes:

    Code:
    (setq laylist2 (car (vl-remove laylist1 (list laylist1 layall))))
    (foreach x laylist1 (setq laylist2 (vl-remove x laylist2)))

  5. #5
    Member
    Join Date
    2019-05
    Posts
    15
    Login to Give a bone
    0

    Default Re: foreach lay NOT in layerlist

    So the last piece I'm having trouble with is here:
    Code:
    (foreach lay laylist2 													
    	(vl-load-com)
    	(setq activedocument (vla-get-activedocument (vlax-get-Acad-Object)))
    	(setq theblocks (vla-get-blocks activedocument))					;this needs to be: get-block on current layer/"lay"			X)faulty
    	(setq xrlist '())													
    	(vlax-for item theblocks
    		(setq yesxref (vlax-get-property item 'isXref))
    		(if (= yesxref :vlax-true)				
    			(progn
    				(setq ablock (vlax-get-property item 'Name))
    				(setq xrlist (append (list ablock) xrlist))			;establish xrlist - list of xrefs on layers belonging to laylist2
    			);progn
    		);if
    	);vlax-for
    );foreach
    At the moment it's getting all blocks in the whole active document, but I want it to be getting only the blocks on each "lay"(layers in laylist2)..
    And then if those are xrefs, add them to the list: xrlist.

    So something like this??
    Code:
    (setq activedocument (vla-get-activedocument lay (vlax-get-Acad-Object)))
    (setq theblocks (vla-get-blocks activedocument))

  6. #6
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    560
    Login to Give a bone
    0

    Default Re: foreach lay NOT in layerlist

    Just a side issue "item" is a word used in VL functions maybe call it something else in your code like xitem

  7. #7
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: foreach lay NOT in layerlist

    Perhaps it would be simpler to iterate Blocks to test for IsXref, then if a valid selection set for XREFs exists, iterate the selection to test for invalid Layer & simply return the list:

    Code:
    (vl-load-com)
    
    (defun _GetXrefsNotOn (layers / *error* xrefs ss name)
      ;; Example:
      ;; (_GetXrefsNotOn '("XREF-IMG-FRT" "XREF" "XREF-IMG-BCK"))
    
      (defun *error* (msg)
        (if ss (vla-delete ss))
        (cond ((not msg))                                                   ; Normal exit
              ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
              ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
        )
        xrefs
      )
      
      (vlax-for x (vla-get-blocks
                    (setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
                  )
        (if (= :vlax-true (vla-get-isxref x))
          (setq xrefs (cons (vla-get-name x) xrefs))
        )
      )
      (if
        (ssget
          "_x"
          (list
            '(0 . "INSERT")
            (cons
              2
              (vl-string-right-trim
                ","
                (apply
                  'strcat
                  (mapcar
                    (function (lambda (x) (strcat x ",")))
                    xrefs
                  )
                )
              )
            )
            '(410 . "Model")
          )
        )
         (progn
           (setq xrefs nil)
           (vlax-for x (setq ss (vla-get-activeselectionset acDoc))
             (if
               (and
                 (not (vl-position (vla-get-layer x) layers))
                 (not (vl-position (setq name (vla-get-name x)) xrefs))
               )
               (setq xrefs (cons name xrefs))
             )
           )
         )
      )
      
      (*error* nil)
    )
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  8. #8
    Member
    Join Date
    2019-05
    Posts
    15
    Login to Give a bone
    0

    Default Re: foreach lay NOT in layerlist

    Sorry... I'm a little confused. How does it know which are the right and wrong layers for all xrefs to be on? Where have you input the list of correct layers?

  9. #9
    Member
    Join Date
    2019-05
    Posts
    15
    Login to Give a bone
    0

    Default Re: foreach lay NOT in layerlist

    I think i've made it work... I had to enter the list in myself right?

    Also, could you tell me what the line in bold is doing here?
    Code:
             (if
               (and
                 (not (vl-position (vla-get-layer x) laylist1))
                 (not (vl-position (setq name (vla-get-name x)) xrefs))
    I understand the other one is saying "if not on any layers from the given layer list", but what is the following if for?

    Thanks

  10. #10
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: foreach lay NOT in layerlist

    Quote Originally Posted by mruu88781911 View Post
    Sorry... I'm a little confused. How does it know which are the right and wrong layers for all xrefs to be on? Where have you input the list of correct layers?
    The sub-function above requires a single argument - a list of layer names - which allows you (or anyone else) to define the appropriate list, as shown in the commented 'example'.

    Quote Originally Posted by mruu88781911 View Post
    I think i've made it work... I had to enter the list in myself right?

    Also, could you tell me what the line in bold is doing here?
    Code:
             (if
               (and
                 (not (vl-position (vla-get-layer x) laylist1))
                 (not (vl-position (setq name (vla-get-name x)) xrefs))
    I understand the other one is saying "if not on any layers from the given layer list", but what is the following if for?
    The second test expression you've bolded is to preclude duplicates from being added to the list of XREFs.

    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

Similar Threads

  1. Possible "foreach" help and filtering of polylines
    By ReachAndre in forum AutoLISP
    Replies: 3
    Last Post: 2013-10-10, 09:45 PM
  2. Replies: 0
    Last Post: 2013-05-05, 03:15 AM
  3. 2012: Lay-out doesn't scale right
    By progvincent366869 in forum AutoCAD General
    Replies: 2
    Last Post: 2013-03-23, 03:14 PM
  4. End of foreach function
    By marko_ribar in forum AutoLISP
    Replies: 11
    Last Post: 2011-02-09, 07:45 PM

Posting Permissions

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