Tool Palettes - Inserting blocks with LISP commands

Tool Palettes - Inserting blocks with LISP commands

jfrog
Enthusiast Enthusiast
6,745 Views
14 Replies
Message 1 of 15

Tool Palettes - Inserting blocks with LISP commands

jfrog
Enthusiast
Enthusiast

Hi there -

 

I'm undergoing the painful process of bringing our company from AutoCAD 2002 to 2015/2016.  As an electrical engineer, I'm always adding device symbols to drawings.  In 2015/2016, it appears that the tool palettes are designed for this.  However, in 2002, our menu files were written with commands to do things like, for example:

 

a)  change to the appropriate layer

b)  set ORTHO to ON

c)  prompt for block insert location

d)  insert the block, (OSNAP'ed to object in drawing)

e)  return ORTHO to previous state

 

In appears that the tools in the tool palettes can either insert a symbol, (1st screenshot below) or run commands (like a LISP program), as the 2nd screenshot.

 

Is there a way to accomplish both?

 

 

0 Likes
Accepted solutions (3)
6,746 Views
14 Replies
Replies (14)
Message 2 of 15

Anonymous
Not applicable
Accepted solution

You can probably use more than 1 command or Lisp in the command bar. 

Your command string would be multiple commands, since you want to remember the ortho mode I would recommend Lisp instead of commands. 

 

The steps you asked for would look something like this:

(defun (/ OM pt) ;starts a lisp program, resets OM and pt when done
	(setq OM (getvar "orthomode")) ;remembers the current orthomode and save that as OM
	(command "-layer" "make" "XXX" "") ; sets layer XXX current or if not there makes layer XXX
	(setq pt (getpoint "\nSpecify insertion point: ")) ; ask the user for insertion point and saves that as pt
	(command "-insert" "C:\\BLOCKLOCATION\\BLOCKLOCATION\\BLOCKNAME.dwg" pt "" "" "" ); Inserts a block from a certain location inserted on predefined pt. (ignores scaling and rotation)
	(setvar "orthomode" OM); sets Orthomode back to what it was
);defun; ends the program

Note that file locations always need \\ instead of / in a lisp.

 

However as a fellow electrical engineer, if you have some knowledge of lisp I would recommend to build this out a bit more, some options:

- Scale your block according to the annotation scale

- Add the folder of your blocks to your working support file search path so you don't need to type the full string every time.

- Make a possibility to rotate the block after insertion (rotate command with the used pt as rotation point).

- Make the program repeat itself until the user pres escape or cancel so you can put in more than 1 symbol in a row.

- Make 1 big placement program, use the button's to define layer, block and start the program.

 

Hope this helps you out a bit, if not please ask.

 

 

 

 

Message 3 of 15

jfrog
Enthusiast
Enthusiast

That's pretty much the way I've got my Acad 2002 menus set up...I was hoping that using the tool palettes I would have better options. 

0 Likes
Message 4 of 15

ВeekeeCZ
Consultant
Consultant

If you can spare the ortho change, then it could be done with ToolPalettes. What is the ortho good anyway... in this case? Maybe for rotation?

0 Likes
Message 5 of 15

jfrog
Enthusiast
Enthusiast

The reason for the "ortho on" is because we're inserting symbols, such as power receptacles or light switches, and placing them on walls in a floor plan.  They get placed in different orientations, but always orthogonally.   Also, with many of my symbols I use an Object Snap to NEAREST.

0 Likes
Message 6 of 15

dgorsman
Consultant
Consultant
Accepted solution

Given the option, I would change things around a bit.  Rather than have a macro string or series of LISP function calls in the UI element, use LISP to define a command line command (i.e. (defun c:SomeCommandNameHere ( / ) ).  Then create a command element in the Tool Palette which calls that command "SomeCommandNameHere".  While you're at it, define a command for it in a partial CUIx as well so it can be added to a Ribbon panel, toolbar, menu, and wherever else it might be needed.

 

Putting all of the logic in code rather than the UI makes it easier to make changes, especially repetitive ones.  Lets say you are changing a layer name from E-WIRE to E-WIRE-FIELD; if you have that layer name scattered all over your palettes with blocks (either direct insert, or via macro/LISP function) that's a *lot* of work.  If you have it in a common code function you only need to change it in one place.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


0 Likes
Message 7 of 15

jfrog
Enthusiast
Enthusiast

Thanks for the input, dgorsman.  I've done it both ways, and was leaning towards putting code in each tool instead of writing a dedicated routine for each symbol, but it's probably the same amount of work anyway, and as you pointed out the dedicated routines are more versatile anyway.

0 Likes
Message 8 of 15

ВeekeeCZ
Consultant
Consultant
Accepted solution

You can make your insertion lisp as universal as possible, then just fill parameters to table structure. Just to get an idea...

Or fill it up in excel, save it as *.csv, then make a sub which reads a csv to list...

 

(vl-load-com)
				name		lay		osm	osm 	ort	scl 	rot
(defun c:ISwire 	nil (InsertSymbol 	"wire" 		"PRW" 	512	nil 	1	0	))
(defun c:ISsocket 	nil (InsertSymbol 	"socket" 	"PRW" 	nil	nil 	1	nil	))






(defun InsertSymbol (name lay osm ort scl rot / adoc oVAR nVAR)

    (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (mapcar 'setvar nVAR oVAR)
    (vla-endundomark adoc)
    (princ))
  
  (vla-startundomark (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
  (setq oVAR (mapcar 'getvar (setq nVAR '(CLAYER CMDECHO OSMODE ORTHOMODE))))

  (if osm (setvar 'OSMODE osm))
  (if ort (setvar 'ORTHOMODE ort))
  
  (command "_.-INSERT"
           name)
  (princ "\nInsertion point: ")
  (command PAUSE
           scl
           scl)
  (if rot
    (command rot)
    (command PAUSE))
  (princ)
)

 

Message 9 of 15

jfrog
Enthusiast
Enthusiast

I've marked several of the responses as solutions, because it appears that the most expedient way to accomplish what I need is to make a generic LISP to install blocks.  Using several of the ideas of you responders and some LISP code I've previously developed, I've done that.  Thanks to you who took the time to respond.

 

I have a follow up question though:  One of the reasons I was trying to use the block insert form of the tool palette was so that the tool's image would be the block itself.  It appears that if you use a command, the image has to be some sort of graphic file, like a jpg, png or whatever.  I really don't want to have to create a bunch of jpg's if I can avoid it. 

 

Backstory:  A former employee created a bunch of tool palettes to insert blocks, and the image is the symbol itself.  It looks nice, but the tools don't do all of the things I want, setting Ortho, snapping, and all the things mentioned in the original post.

 

Is there a way to use the block as the image?

0 Likes
Message 10 of 15

scot-65
Advisor
Advisor
I have a program that I developed that would suggest
yet another method for inserting blocks where the library
folder contents is constantly changing.

By taking what I have developed and further added elements
to your situation, here is a conceptual design of this program:

Create a dialog (DCL) with a list box and a few toggles.
Insert / Cancel / Help buttons to finish.

Using the VL functions, create a LIST of all DWG files in a
given folder and populate the list box.

If the folder is a "moving target", add to the DCL a
edit box and "Browse for Folder" button. Save this
path in the Registry (HKCU).

If there are multiple folders to look, then "build on the fly"
the DCL with radio buttons so the user can select which
folder to select; so the list box can be populated.

A sub-DCL can be used to manage the registry entries that
contain the hard-path-prefix to each folder.

If you are clever enough, allow the DCL to be positioned
anywhere on the screen and record the position to the
registry for next use.

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 11 of 15

Anonymous
Not applicable

With the amount of searching I did for exactly that in the past I am pretty sure dwg preview in pallets and dcl/lisp file's is not part of Acad and would be a really nice addition for future releases. 

For our company I created 1 library dcl + lisp file which I can use for all library and created a sld file for all blocks. hell of a job but performance is rock solid.

 

 

0 Likes
Message 12 of 15

ВeekeeCZ
Consultant
Consultant

@jfrog wrote:

 

...

I have a follow up question though:  One of the reasons I was trying to use the block insert form of the tool palette was so that the tool's image would be the block itself.  It appears that if you use a command, the image has to be some sort of graphic file, like a jpg, png or whatever.  I really don't want to have to create a bunch of jpg's if I can avoid it. 

 

Backstory:  A former employee created a bunch of tool palettes to insert blocks, and the image is the symbol itself.  It looks nice, but the tools don't do all of the things I want, setting Ortho, snapping, and all the things mentioned in the original post.

 

Is there a way to use the block as the image?


Create a TEST palette. Drag n drop all the blocks from your Explorer on this palette (works all at once, from DesignCentre probably one by one only), then Right click on any of new tools, Specify Image..., there you can see the path where were png image files created. Dark and Light.

Message 13 of 15

Anonymous
Not applicable

With the amount of searching I did for exactly that in the past I am pretty sure dwg preview in pallets and dcl/lisp file's is not part of Acad and would be a really nice addition for future releases. 

For our company I created 1 library dcl + lisp file which I can use for all library and created a sld file for all blocks. hell of a job but performance is rock solid.

 

0 Likes
Message 14 of 15

jfrog
Enthusiast
Enthusiast

@ВeekeeCZ wrote:

Create a TEST palette. Drag n drop all the blocks from your Explorer on this palette (works all at once, from DesignCentre probably one by one only), then Right click on any of new tools, Specify Image..., there you can see the path where were png image files created. Dark and Light.


Thanks! That does the trick! 

0 Likes
Message 15 of 15

jfrog
Enthusiast
Enthusiast

@Anonymous wrote:

With the amount of searching I did for exactly that in the past I am pretty sure dwg preview in pallets and dcl/lisp file's is not part of Acad and would be a really nice addition for future releases. 

For our company I created 1 library dcl + lisp file which I can use for all library and created a sld file for all blocks. hell of a job but performance is rock solid.

 


That's essentially what our company currently has.  Someone developed the slides in the early 90's, and they work great...Escept that they're just really difficult to edit and update.  The palettes seem like a great update.

0 Likes