Jump to content

Recommended Posts

Posted

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

Posted

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.

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

 

can you upload the drawing for us my friend?

Posted

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.

Posted

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

Posted

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.

Posted

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

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