Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Inert a block definition from a file our server into the current draing

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
cchiles
404 Views, 10 Replies

Inert a block definition from a file our server into the current draing

Morning all,

I have a REV tag block that is insertable through the palettes (from the file "S:\Block Library\JST\tags.dwg" but I would like to create a lisp to insert it thorugh a quick short cut as well.

 

I've work on this for a couple hours now trying all sorts of methods and this is what I've come up with:

 

(defun c:rt (/ p blk sc)
  (setq p (getpoint "\n Select insertion point... :"))
    (setq sc (getvar 'dimscale))    
         (command "insert" "jst revision mark.dwg" P SC "" "")
          (princ)
)

 This work very well as long as the block definition is in the current drawing, if not the following is returned:

..."jst revision mark.dwg": Can't find file in search path:...

 

I do have "S:\Block Library\JST" in my support paths...

 

As A work around I also tried creating a dwg tiled "jst revision mark.dwg" and placing that the S drive folder, but when I do I recieve the following error:

...S:\Block
Library\JST\jst revision mark.dwg Block jst revision mark references itself
*Invalid*...

Can somone please explain how it's referencing it's self?

 

 

But more importantly, how to do I have the routine look to "S:\Block Library\JST\tags.dwg" for the definition and then insert that?

 

Thanks,

Chris

 

Thanks in advance!
-Chris
Tags (3)
10 REPLIES 10
Message 2 of 11
Kent1Cooper
in reply to: cchiles


@cchiles wrote:

....

 how to do I have the routine look to "S:\Block Library\JST\tags.dwg" for the definition and then insert that?

....


If you want the Block name in the drawing to be different from the drawing name it comes from:

 

(command "insert" "jst revision mark=tags" P SC "" "")

 

I am assuming there will be no tags.dwg in any location higher up in the Support File Search Path list than the one you want.

 

That may have a problem if you run it again, with such a Block name already defined, because it will want to know whether you want to redefine it.  Any reason not to just use "tags" as the Block name in the drawing?  If you do that, you can just do:

 

(command "insert" "tags" P SC "" "")

 

and if it's already in the drawing, it will use that definition, but if it's not, it will go looking for it in the Support File Search Paths under that as a drawing name.

 

The .dwg filetype ending is not necessary in any of this -- that's the only kind of file it will look for.

Kent Cooper, AIA
Message 3 of 11
hmsilva
in reply to: cchiles

If I understood correctly, perhaps something like this

 

(defun c:rt (/ p blk sc)
  ;; test for a valid point
  (if (and (setq p (getpoint "\n Select insertion point... :"))
	   (setq sc (getvar 'dimscale))
      )
    ;; search if the block definition exist
    (if	(tblsearch "block" "jst revision mark")
      ;; if true inserts the block
      (command "insert" "jst revision mark" P SC "" "")
      ;; if not true test if find the main dwg
      (if (findfile "S:\\Block Library\\JST\\tags.dwg")
	(progn
	;; if true inserts the main dwg
	(command "insert" "S:\\Block Library\\JST\\tags" p)
	;; cancel the insertion, but the definition remains...
	(command)
	;; inserts the block
	(command "insert" "jst revision mark" P SC "" "")
	)
      )
    )
  )
  (princ)
)

 

Without importing all settings from the main dwg, you can take a look at Lee Mac's Import Block and use is routine to import just the block definition.

 

HTH

Henrique

EESignature

Message 4 of 11
Kent1Cooper
in reply to: cchiles


@cchiles wrote:

.... 

As A work around I also tried creating a dwg tiled "jst revision mark.dwg" and placing that the S drive folder, but when I do I recieve the following error:

...S:\Block
Library\JST\jst revision mark.dwg Block jst revision mark references itself
*Invalid*...

Can somone please explain how it's referencing it's self?

.... 


Some clarification needed, from the above and from hmsilva's suggestion:  Some other things in what you've described make it sound like [my assumption in my previous Reply] the "tags.dwg" file is the definition of what you want to use as the "jst revision mark" Block.  But from these other considerations, now I'm wondering whether "jst revision mark" is one Block definition [presumably among others] inside the "tags.dwg" file.  If the latter is the case, then what I suggested before won't work, and I think it explains the references-itself problem, if your "jst revision mark.dwg" is a copy of "tags.dwg".  If that's what's happening, I think hmsilva's suggestion may be the way to go if you want a routine defined, but you can also do it without any code, using the Design Center [ADC command] to pull a Block definition from another drawing.

Kent Cooper, AIA
Message 5 of 11
cchiles
in reply to: hmsilva

Hey thanks Henrique - that works great!
One questions - at the end of the routine it returns:
"RT Unknown command "RT". Press F1 for help."
Why is that?

Thanks in advance!
-Chris
Message 6 of 11
cchiles
in reply to: Kent1Cooper

Thanks for the clarification Kent. Yes, I wanted to pull the definition from TAG.dwg (if it wasn't already in the current drawing) and insert it. So Henrique's worked great! Thanks for the help.
Thanks in advance!
-Chris
Message 7 of 11
Kent1Cooper
in reply to: cchiles


@cchiles wrote:
Hey thanks Henrique - that works great!
One questions - at the end of the routine it returns:
"RT Unknown command "RT". Press F1 for help."
Why is that?


Sounds like too many Enters in the Insert command.  Is the Block defined to always be uniformly scaled?

Kent Cooper, AIA
Message 8 of 11
cchiles
in reply to: cchiles

Here's my code as it stands:

 

;;;Insert Revision Mark
;;;Checks for RevCloud Layer A-Rev (Sets it current) & Create it if it's not there.
;;;Inserts "JST Revision Mark" from S:\Block Library\JST\Tags.dwg & Scales to current Dimscale
(defun c:rt (/ cl p sc)
;;;Gets Current Layer
(setq CL (getvar "clayer"))
;;;Searches for Layer "A-REV"
(if (tblsearch "layer" "A-REV")
	(setvar "clayer" "A-REV")
	(command "_.-layer" "_make" "A-REV" "_color" "5" "" "")
	)
;;;End of Search
  ;; test for a valid point
  (if (and (setq p (getpoint "\n Select insertion point... :"))
	   (setq sc (getvar 'dimscale))
      )
    ;; search if the block definition exist
    (if	(tblsearch "block" "jst revision mark")
      ;; if true inserts the block
      (command "insert" "jst revision mark" P SC "" "")
      ;; if not true test if find the main dwg
      (if (findfile "S:\\Block Library\\JST\\tags.dwg")
	(progn
	;; if true inserts the main dwg
	(command "insert" "S:\\Block Library\\JST\\tags" p)
	;; cancel the insertion, but the definition remains...
	(command)
	;; inserts the block
	(command "insert" "jst revision mark" P SC "" "")
	)
      )
    )
  )
  ;;;Reset Current Layer
(setvar "clayer" CL)
  (princ)
)

 I added a look up for layer "A-rev", if not there then create it. Then reset to previous layer.

 

Thanks Y'all.

Chris

Thanks in advance!
-Chris
Message 9 of 11
cchiles
in reply to: Kent1Cooper

Yes it is Kent.

Thanks in advance!
-Chris
Message 10 of 11
Kent1Cooper
in reply to: cchiles


@cchiles wrote:

Yes it is Kent.


Then the SC in each Insert command would cover both X and Y scale factors, the first "" that would otherwise be for the Y scale factor should be removed, and the second "" should remain as the default Rotation of zero.

Kent Cooper, AIA
Message 11 of 11
hmsilva
in reply to: cchiles


@cchiles wrote:
Hey thanks Henrique - that works great!
One questions - at the end of the routine it returns:
"RT Unknown command "RT". Press F1 for help."
Why is that?


You're welcome, cchiles.

Glad I could help!

 

As Kent1Cooper already pointed out, the "RT Unknown command "RT". Press F1 for help." should result from an extra enter at the insert command, to prevent it change the

(command "insert" "jst revision mark" P SC "" "")

to

(command "insert" "jst revision mark" "_S" SC "_R" 0 P)

 

HTH

Henrique

 

 

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost