+ Reply to Thread
Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 11 to 20 of 30
  1. #11
    Senior Member
    Computer Details
    feargt's Computer Details
    Operating System:
    win 7
    Using
    Civil 3D 2012
    Join Date
    Sep 2008
    Location
    Austria
    Posts
    428

    Default

    Registered forum members do not see this ad.

    Thanks Tharwat,


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


    Code:
    ........(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

  2. #12
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,359

    Default

    I would suggest something like:
    Code:
    (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)
    )
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  3. #13
    Senior Member
    Computer Details
    feargt's Computer Details
    Operating System:
    win 7
    Using
    Civil 3D 2012
    Join Date
    Sep 2008
    Location
    Austria
    Posts
    428

    Default

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

  4. #14
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,084

    Default

    Quote Originally Posted by feargt View Post
    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.

    Code:
    (defun c:test (/ lst fnd pth)
      ;; Tharwat 23.06.2015 ;;
      (setq lst '(("Xref_1_ELC" "Xref_1_ELC_Sub1") ("Old" "New")))
      (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)

  5. #15
    Senior Member
    Computer Details
    feargt's Computer Details
    Operating System:
    win 7
    Using
    Civil 3D 2012
    Join Date
    Sep 2008
    Location
    Austria
    Posts
    428

    Default

    Thanks Tharwat,


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


    Code:
    (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


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

  6. #16
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,084

    Default

    Quote Originally Posted by feargt View Post

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

    Code:
    )(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.

    Code:
    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,"

  7. #17
    Senior Member
    Computer Details
    feargt's Computer Details
    Operating System:
    win 7
    Using
    Civil 3D 2012
    Join Date
    Sep 2008
    Location
    Austria
    Posts
    428

    Default

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




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

  8. #18
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,084

    Default

    Quote Originally Posted by feargt View Post
    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 ?

  9. #19
    Senior Member
    Computer Details
    feargt's Computer Details
    Operating System:
    win 7
    Using
    Civil 3D 2012
    Join Date
    Sep 2008
    Location
    Austria
    Posts
    428

    Default

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

  10. #20
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,084

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by feargt View Post
    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.

Similar Threads

  1. Modify xref path in Acad LT 2012
    By deano33 in forum AutoCAD Drawing Management & Output
    Replies: 1
    Last Post: 20th Jun 2012, 05:46 pm
  2. Replies: 0
    Last Post: 23rd Nov 2011, 03:16 am
  3. Xref Drawing List
    By TomC in forum AutoCAD Drawing Management & Output
    Replies: 2
    Last Post: 23rd Dec 2009, 06:24 am
  4. Modify, bind, Explode XREF?
    By mikew0ng in forum AutoCAD Beginners' Area
    Replies: 2
    Last Post: 14th Aug 2006, 10:08 pm
  5. Modify > In place xref and block edit
    By edortizr6 in forum AutoCAD Beginners' Area
    Replies: 5
    Last Post: 26th Jul 2006, 02:00 pm

Tags for this Thread

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