DD21988 发表于 2022-7-5 19:44:34

XIMPORT dosen't see block

I am trying to write a lisp routine that would import blocks from another drawing by attaching the drawing as an xref, xbinding the selected blocks and detaching the xref. When I run the lisp, it says that the drawing file I type in is already attached as xref or has no blocks (both of which are not true). Any idea what's wrong? Below is the code. (tried to wrap code in tags, but no matter how often I highlight the code and hit the tag button it doesn't show. Sorry)
 
 
 
 
(defun C:XIMPORT ( / fname blname toggle nlist index blist)
(setq fname (ustr 1 "Enter filename to extract block from" nil nil))
(while (tblnext "block"))
(command "xref" "a" fname nil)
(tblnext "block")
(while (setq blname (tblnext "block"))
    (setq blist (append (list (dxf 2 blname)) blist))
)
(if blist
    (progn
      (textpage)
      (setq index -1)
      (while (setq index (1+ index) blname (nth index blist))
      (setq toggle (not toggle))
          (prompt
            (strcat (if toggle "\n " "\t\t") (itoa (1+ index)) " " blname)
      ) );while&prompt
      (while (setq index
                (getint
                  "\nEnter block number to import or Enter to exit : "
      )         )
      (setq blname (nth (1- index) blist))
      (setq nlist (append (list (nth (1- index) blist)) nlist))
   );while
   (foreach blname nlist (command "xbind" "b" blname))
   (command "xref" "d"
       (progn (textpage)
(prompt "\n\nItems listed as Not Detached show assigned names of imported blocks:\n\n")
          fname
      ) )
    );progn then
    (prompt (strcat "\n" fname " already attached as xref or has no blocks."))
);if blist
(princ)
);defun C:XIMPORT

DD21988 发表于 2022-7-5 19:56:26

I forgot to post a subroutine I have built into this lisp. It is as follows:
 
 
;* USTR: User interface string
;* If BIT=1 no null "" input allowed, 0 for none, BIT ignored if DEF present.
;* MSG is the prompt string, to which a default string is added as(nil
;*or "" is for none), and a : is added. If SPFLAG T, spaces are allowed in string.
 
(defun ustr (bit msg def spflag / inp nval)
   (if (and def (/= def ""))
       (setq msg (strcat "\n" msg ": ")
               inp (getstring spflag msg)
               inp (if (= inp "") def inp)
       );setq
       (progn
         (if (= " " (substr msg (strlen msg) 1))
             (setq msg (strcat "\n" (substr msg 1 (1- (strlen msg))) ": "))
             (setq msg (strcat "\n" msg ": " ))
    );if
    (if (= bit 1)
      (while (= "" (setq inp (getstring spflag msg)))
          (prompt "\nInvalid string.")
      )
      (setq inp (getstring spflag msg))
      ) );progn&if
    );if
    inp
);defun
;*
 
 
Again, any help would be appreciated.

ttray33y 发表于 2022-7-5 20:09:27

 
can you upload the drawing for us my friend?

DD21988 发表于 2022-7-5 20:18:15

I apologize, but I don't know how to post a dwg. to this site. Could you point me to a how to or explain it. Still really new here.

ttray33y 发表于 2022-7-5 20:25:38

just replay via the "Go Advanced" Button, then you can find the "Manage Attachments" button there

DD21988 发表于 2022-7-5 20:32:49

Ok, let me know if this didn't work.
TEST.dwg

ttray33y 发表于 2022-7-5 20:36:08

now I see, paperspace objects cant be imported to a drawings thru xref.
you may try putting those objects to Model space and rety your routine.

DD21988 发表于 2022-7-5 20:46:17

I copied the blocks into the model space and tried again, but got the same error. I attached the new dwg. into this post. Any other ideas?
TEST.dwg
页: [1]
查看完整版本: XIMPORT dosen't see block