Jump to content

Recommended Posts

Posted

my line of thining was the following

 

 

Get list of Xref names with "*_ELC" at the end

 

 

For each Xref in list

get Insertion Point

insert first new xref at Insertion Point

insert second new xref at Insertion Point

  • Replies 29
  • Created
  • Last Reply

Top Posters In This Topic

  • feargt

    16

  • Tharwat

    11

  • Lee Mac

    3

Top Posters In This Topic

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

 

 

 

but wont that only work with an Xref that already exists in my drawing?

Posted

insert first new xref at Insertion Point

insert second new xref at Insertion Point

 

Can you explain these two phrases a little bit more ?

Posted

for example

 

 

XREF_1_ELC and XREF_2_ELC exist in my drawing .

 

 

they will be replaced with 2 Xrefs each

 

 

XREF_1_ELC_Sub_1 & Xref_1_ELC_Sub_2

 

 

XREF_2_ELC_Sub_1 & Xref_2_ELC_Sub_2

 

 

These must be inserted at the same Insertion Point as the original XREF

Posted
for example

 

XREF_1_ELC and XREF_2_ELC exist in my drawing .

 

they will be replaced with 2 Xrefs each

 

XREF_1_ELC_Sub_1 & Xref_1_ELC_Sub_2

 

XREF_2_ELC_Sub_1 & Xref_2_ELC_Sub_2

 

These must be inserted at the same Insertion Point as the original XREF

 

So did you or were you able to test the program that I posted in post No# 14 ?

Posted

no, I didn't test it because that will only replace the existing Xref, and will not insert the second xref

Posted
no, I didn't test it because that will only replace the existing Xref, and will not insert the second xref

You are wrong , as I said before after running the program you need to save and close and open the drawing again to see the changes .

Posted

(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)

 

 

"Xref_1_ELC" needs to be replaced by 2 Xrefs"Xref_1_ELC_Sub1" and "Xref_1_ELC_Sub_2"

 

 

 

 

 

 

on a side note:

adding (vla-reload blk) to the end of the code would probably avoid having to save and reopen the drawing to see the Change

 

 

http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vla-put-path/td-p/3312595

Posted

by the way I do really appreciate your assistance on this!

Posted

(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)
)

 

 

 

 

was able to solve my problem using the code from Lee Mac by making the following modifications which gave the Name and the Insertion Point. Then while in the Repat funtion I was able to add my xrefs using the Insertion Point and delete the original.

 

 



(defun c:findxref ( / idx ins sel td xrf xrn [color=red]Xrn2 xrefN[/color][color=red] Path[/color])
 [color=red](setq pfad "C:/XXXX/Xrefs/")[/color]
    (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))
                [color=red](setq ins (cadr (assoc 10 (entget (ssname sel (setq idx (1- idx)))))))[/color]
               [color=red](setq xrn2 (cdr (assoc 2 (entget (ssname sel idx)))))[/color]
[color=#ff0000]                (print (strcat xrn2 " at " (rtos x)))[/color]
[color=#ff0000]        (setq xrefn (vl-string-subst "_ELC_Sub1.dwg" "_ELC" (strcase xrn2)))[/color]
[color=red]       (if (findfile (strcat pfad xrefn)) (command "_.-XREF" "_overlay" (strcat pfad xrefn) (strcat (rtos x) ",0,0") "1" "1" "0"))[/color]
[color=#ff0000](setq xrefn (vl-string-subst "_ELC_Sub2.dwg" "_ELC" (strcase xrn2)))
[color=red]       (if (findfile (strcat pfad xrefn)) (command "_.-XREF" "_overlay" (strcat pfad xrefn) (strcat (rtos x) ",0,0") "1" "1" "0"))[/color][/color]
[color=#ff0000][/color]
            )
            
        )
        (princ "\nNo xrefs found.")
    )
    (princ)
)

Probably not the most eloquent method but it achieves the purpose!!

 

 

Thanks again for all your help Tharwat and Lee!

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...