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

LISP Routine to interact with a Tool Palette?

5 REPLIES 5
Reply
Message 1 of 6
chadmart
1256 Views, 5 Replies

LISP Routine to interact with a Tool Palette?

I have a LISP that inserts a point at a particular point and angle, based on user input. What I would like is for that same lisp to instead, insert a block. I got it to work by typing in the block name, but the problem is that when I start a drawing not all of my blocks are inserted. I use tool palettes to insert the blocks typically. What I would like is for the LISP to insert the block that I select from the tool palette. Is that possible? (Original LISP attached, the one that inserts a point. It has code in it to insert a block by selecting that block, but it didn't work very well. I have a version where I type in the block name, but again I have the problem I stated where not all blocks are active in the drawing.)

 

Thanks!

5 REPLIES 5
Message 2 of 6
rapidcad
in reply to: chadmart

I looked at your lisp a little - seems like you had something working somewhat. Why not set the blockname as a variable by having the user pick it from a list by keyword, or by a dialog box?

 

Or another way is to load your lisp with a palette tool with a line of code like this:

^C^C(setq blockname "yourblock'sname)(load "TOPO");TOPO;

 

and put the block name variable in your lisp in place of the (entsel "Pick a Block")

 

However, you will need to do some more with the code if you are going to bulletproof the using of the -insert command from the tool palettes.

 

But first step is, find a palette tool in the Autodesk provided example tool palettes and copy it to your tool palette if you do not have a lisp loading  palette tool.

 

 

ADN CAD Developer/Operator
Message 3 of 6
chadmart
in reply to: rapidcad

Being able to pick the block name from a list or using a dialogue box would be great, but where would ACAD get that list? Would it be built into the LISP, meaning that if I add or remove blocks then I need to adjust the LISP? Or would the LISP just grab a list of all current blocks that are active in the drawing? That approach I could probably make work.

Message 4 of 6
vivifira
in reply to: chadmart

Hi chadmart,

I'm working on a lisp that is doing something similar but I'm using an array after I insert the block. you can invoke the insert command by adding the line (command ".-insert"). you can also add parameters like previously selected points and block names. for example (command ".-insert" bl p1 p2 1 1 "90" "") where p1 p2 are previously selected point with the getpoint function and bl is the block name in the drawing selected by the initget and getkword functions. I hope this helps.
Message 5 of 6
rapidcad
in reply to: chadmart

Well, practical use of certain methods would depend on a few factors. For instance, if we are talking about three or four blocks to choose from, the keyword method might be easy and for the user, simple. I'd have to refresh my memory on how to set it up for choosing blocknames - I remember it uses the initget keyword string function.

 

As far as getting your blocks into your drawing, there are several ways to do it. If the blocks are really simple and small in data footprint, and if it does not hurt to have them in every drawing, you could simply insert them into your company template,  and even delete them (if you are confident that they won't get purged). their definition would then reside in every new drawing. AutoCAD does this already with some dimension arrowheads (_none). Otherwise, you could add your path to the folder containing the point blocks to your OPTIONS>FILES>SUPPORT FIES SEARCH PATH folders and AutoCAD will find them there. Another simple method is to store the path as a variable - for example (setq mypath "C:\\CAD\\STANDARDS\\BLOCKS\\") and then store your block name as a variable like so: (setq blkname "POINT_01.dwg"). These could be inserted by your code.

 

Here's a line of your code revised:

(command "-insert" (strcat mypath blkname) (polar (polar pt1 ang dist) (+ ang (/ pi 2)) off) "1" "1" (+ (* ang (/ 180 pi)) 180))

 

I often combine this technique (using the path as a variable) with palette tool code as I showed in my first reply.

 

The dialogue box is a more complicated way to get there, - you'll need to familiarize yourself with the whole dialogue box code (.dcl) and how to call it  - not real hard to do simple things with it, but it can become difficult to understand when you start getting advanced.

 

If you only have a few blocks, why not create several insertion tools on the tool palette - each one running your lisp on different block names?

 

ADN CAD Developer/Operator
Message 6 of 6
chadmart
in reply to: rapidcad

It's been a while since I last checked in on this discussion. I appreciate all the feedback. The more I think about it, the more I think that there should be a way to do what I want. Here is the order of actions I would like to have happen:

 

Run Topo.lsp.

Select start point,

Select end point (this sets the zero point as well as the angle along which the routine measures)

Type distance

Type offset

Select block (ideally at this point I could move my mouse over to my tool palette, and click on the block that i want)

Then the routine places the selected block at the point specified, aligned with the angle of the line.

Then the routine repeats.

 

The idea is that I stay in the routine and enter each point in my list. If I were to create palette tools that invoked the lisp routine for that particular block, then I would have to run the routine (and pick beginning and end points each time) over and over again. 

 

Based on the responses so far, I am assuming this is a pipe dream. How about the design center? can a lisp routine interact with the design center for the purposes of selecting a block to insert?

 

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

Post to forums  

Autodesk Design & Make Report

”Boost