Jump to content

Modify Xref list


feargt

Recommended Posts

Hi,

 

 

I have a list of Xrefs

 

 

Xref_1 Xref_2 Xref_3_ELC Xref_4_ELC Xref_........

 

 

I want to modify the list to only include items that have_ELC at the end.

 

 

even better would be if i could only add Xrefs to my list that have _ELC at the end.

 

 

both attempts below do not succeed.

 

 

any ideas?

 

 

 

 



(defun c:findxref (/ td xrf)
 (setq XrfM nil)
(while (setq td (tblnext "BLOCK" (not td)))
(and (= (logand (cdr (assoc 70 td)) 4) 4)
(setq xrf (cons (strcase (cdr (assoc 2 td))) xrf))
     )
  )
(print xrf)


;attempt with Vl-remove
(foreach n xrf
  (if (/= (wcmatch n "*_ELC")T) (vlremove n xrf)))




;Create new list
(foreach n xrf
  (if (= (wcmatch n "*_ELC")T) (append n xrfm)))


 (print Xrf)
 (print Xrfm)
 (princ)
)

 

 

 

 

Thanks

Link to comment
Share on other sites

  • Replies 29
  • Created
  • Last Reply

Top Posters In This Topic

  • feargt

    16

  • Tharwat

    11

  • Lee Mac

    3

Top Posters In This Topic

Just a hint here .

 

(if (wcmatch n "*_ELC")
  (setq lst (append lst (list n)))
)

Edited by Tharwat
missing function added
Link to comment
Share on other sites

Thanks for the hint but

it's just not happening for me, what am I missing from your hint?

 

 

 

 

keeps returning Nil for Xrfm

 

 

 

 

 

 

(defun c:findxref (/ td xrf XrfM)
 (setq XrfM '())
(while (setq td (tblnext "BLOCK" (not td)))
(and (= (logand (cdr (assoc 70 td)) 4) 4)
(setq xrf (cons (strcase (cdr (assoc 2 td))) xrf))
     )
  )
(print xrf)
 
(foreach n xrf
  (if (wcmatch n "*_ELC")    
      (setq XrfM (append  n Xrfm))
    
      )
)
 
 (print Xrfm)
 (princ)
)

Link to comment
Share on other sites

I am sorry , I forgot to add the list function for the append function to work with lists .

 

So just add the list function for the n variable to be able to append it to the list .

 

eg.

 

(foreach n xrf
   (if (wcmatch n "*_ELC")
     (setq XrfM (append Xrfm (list n)))
   )
 )

Link to comment
Share on other sites

Rather than removing the unwanted items from the resulting list, I would instead suggest omitting them within the initial loop, e.g.:

(defun c:findxref ( / td xrf xrn )
   (while (setq td (tblnext "block" (not td)))
       (and (= (logand (cdr (assoc 70 td)) 4) 4)
            (wcmatch (setq xrn (strcase (cdr (assoc 2 td)))) "*_ELC") ;; Must pass this criteria before being added to the list
            (setq xrf (cons xrn xrf))
       )
   )
   (print xrf)
   (princ)
)

Link to comment
Share on other sites

Hi again, related to same why am I getting an error message here

 

 

I am trying to retrieve the X value of the Insertion Point of the xrefs in my list,

but it returns an error. If i try Option 2 and enter the Xref Name at Position "n" and only enter that on the command line, then it works. any ideas what I am missing here

 

 

(foreach n xrf
   
[color=red]OPTION 1[/color]
  (setq ss (ssget "X" '((0 . "INSERT")(67 . 0)(2 . n)))) 
(setq x (car (cdr (assoc 10 (entget ss)))))  
      
[color=red]OPTION 2[/color]
  (setq x (car (cdr (assoc 10 (entget (ssname (ssget "_X" '((2 . n))) 0))))))
 
(print x)

Link to comment
Share on other sites

Thanks Tharwat,

 

 

can u possibly explain what ist Happening in the section .....

 

 

........(apply 'strcat (mapcar '(lambda (x) (strcat x ",")) xrf))))))

 

 

This seems to return only the X value of the first Xref in the list each time and not the x value for the next xref in my list

Link to comment
Share on other sites

I would suggest something like:

(defun c:findxref ( / idx ins sel td xrf xrn )
   (while (setq td (tblnext "block" (not td)))
       (and (= (logand (cdr (assoc 70 td)) 4) 4)
            (wcmatch (setq xrn (strcase (cdr (assoc 2 td)))) "*_ELC") ;; Must pass this criteria before being added to the list
            (setq xrf (vl-list* "," xrn xrf))
       )
   )
   (if (setq sel (ssget "_X" (list '(0 . "INSERT") (cons 2 (apply 'strcat (cdr xrf))))))
       (progn
           (repeat (setq idx (sslength sel))
               (setq ins (cons (cadr (assoc 10 (entget (ssname sel (setq idx (1- idx)))))) ins))
           )
           (print ins)
       )
       (princ "\nNo xrefs found.")
   )
   (princ)
)

Link to comment
Share on other sites

Thanks Lee for your Version.

 

 

might help to explain why I wanted to use for each.

I want to replace the existing xref with two other xrefs, which Need to be inserted at the same Insertion Point (which only varies on the x axis)

 

 

so for example.

Replace Xref_1_ELC

 

 

with Xref_1_ELC_Sub1 and Xref_1_ELC_Sub2

 

 

The new names for the Xref I can get by manipulting the "n"

 

 

(setq xrefn (vl-string-subst "_ELC_Sub1" "_ELC" n)))

 

 

the replacement I think is not a Problem using (command "_.-xref" .......)

Link to comment
Share on other sites

I want to replace the existing xref with two other xrefs, which Need to be inserted at the same Insertion Point (which only varies on the x axis)

 

so for example.

Replace Xref_1_ELC

 

with Xref_1_ELC_Sub1 and Xref_1_ELC_Sub2

 

You can add as many as you want in the following program as shown in the program eg. ("old" "new") and you need to save and re-open the drawing to see the changes.

 

(defun c:test (/ lst fnd pth)
 ;; Tharwat 23.06.2015 ;;
 (setq lst '(([color=red]"Xref_1_ELC"[/color] [color=blue]"Xref_1_ELC_Sub1"[/color]) ([color=red]"Old"[/color] [color=blue]"New"[/color])))
 (vlax-for blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
   (if (and (= :vlax-true (vla-get-isxref blk))
            (setq fnd (assoc (vla-get-name blk) lst))
            (setq pth (findfile (strcat (cadr fnd) ".dwg")))
       )
     (vla-put-path blk pth)
   )
 )
 (princ)
)(vl-load-com)

Link to comment
Share on other sites

Thanks Tharwat,

 

 

The reason that I was approaching it the way I was with

 

 

(foreach n xrf
   

(setq ss (ssget "_X" (list '(0 . "INSERT")'(67 . 0)(cons 2 (apply 'strcat (mapcar '(lambda (n) (strcat n ",")) xrf))))))
(setq x (car (cdr (assoc 10 (entget ss)))))  
      
(print x)


is because I dont know the names of the Xrefs, I only know that they end in "_ELC" and that it Needs to be done to about 150 drawings

 

 

Which is why I wanted to iterate through each Xref in my list, get the insertion point and use that to insert the new xrefs. Each xref will be replaced with 2 xrefs.

The main problem being that the above which you provided is not returning the Insertion Point for each xref ( as in "n") but returns the insertion point for the first Xref in the list each time instead of iterating through them.

 

 

I have not been able to figure this part of the code out

 

 

)(cons 2 (apply 'strcat (mapcar '(lambda (n) (strcat n ",")) xrf))))))

Link to comment
Share on other sites

 

I have not been able to figure this part of the code out

 

)(cons 2 (apply 'strcat (mapcar '(lambda (n) (strcat n ",")) xrf))))))

 

Firstly the mapcar function would append a comma to every name of the xref name that is gathered in the 'xrf" variable , then the apply function with the use of strcat function would gather them as one string to match the criteria needed for the ssget funtion as dxf codes .

 

eg.

 

xrf = ("drawing1" "drawing2" "drawing3")

(mapcar '(lambda (n) (strcat n ",")) xrf)
; return: ("drawing1," "drawing2," "drawing3,")

; then using the apply with strcat function to concatenate them all together .

(apply 'strcat (mapcar '(lambda (n) (strcat n ",")) xrf))
; return: "drawing1,drawing2,drawing3,"

Link to comment
Share on other sites

but then should the following not work? I mean should it not print to the command line the X value of the Insertion Point for each xref in Xrf?

 

 

assuming xrf = ( "Xref_1_ELC" "Xref_2_ELC")

 

 

 

 



 (foreach n xrf
   
   (setq ss (ssget "_X" (list '(0 . "INSERT")'(67 . 0)(cons 2 n))))
  
    (print ss)
      
        (setq x (car (cdr (assoc 10 (entget (ssname n 0))))))

    (print x)

      )

Link to comment
Share on other sites

assuming xrf = ( "Xref_1_ELC" "Xref_2_ELC")

Since you know the old and the new replaced one , you can use the codes that I posted in post No# 14

 

Why you are re-selecting the same block name since that you can make any changes while retrieving it from the block table right away ?

Link to comment
Share on other sites

because I am not just replacing it with another Xref, I also need to insert a second Xref at the same Insertion point

Link to comment
Share on other sites

because I am not just replacing it with another Xref, I also need to insert a second Xref at the same Insertion point

With the function vla-put-path would take care of all and using codes much better than using commands as you are planning to.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...