Need Advice

Need Advice

Anonymous
Not applicable
1,249 Views
9 Replies
Message 1 of 10

Need Advice

Anonymous
Not applicable

I'm trying to create my own lisp (which should be simple) that basically just streamlines a repetitive process  for me instead of me manually doing it several times. I have only been able to get a little less than halfway through it performing the way I want. So just a little about what im trying to do is I am simply adding visibility states to a current dynamic block(simply put). Again, for the most part I want this to be automatic with only one or two steps requiring user input. here are the steps I am looking to achieve which should be pretty simple I thought:

 

1. open block editor for currently selected block -got it

2. activate creation of new visibility state requiring user to name state. - this is where im stuck. it opens and asks for me to name new state but aftwerwards wants me to pick one of the three options [hide all/show all/current visibility]. I want this to be automatic so rest of the code works

3. paste newly copied block into visibility state - got it

4. close the block - got it

 

With my intent in mind here is the code so far:

 

(defun c:AD ()

(command"bedit")

(command"bvstate""new"getkword"h") <------- this is the part that wont function the way I want. The "h" at the end will not function automatically

(command"pasteclip""0,0"

(command"bclose")

(princ)

)

 

Something is not right in the second line and I cannot move to the third line until it is fixed. Ive tried adding parenthesis in different places, adding brackets, etc. I need help!

0 Likes
Accepted solutions (1)
1,250 Views
9 Replies
Replies (9)
Message 2 of 10

Kent1Cooper
Consultant
Consultant

Unless you are using getkword as a variable name, that is set somewhere outside the posted code, then what you show is improper use of it.  It is an AutoLisp function, and needs [like all AutoLisp functions] to be surrounded by opening/closing parentheses and supplied with a Prompt for the user to select from, and  needs to be preceded by an (initget) function to define allowable keywords.  Something like [untested]:

 

....

(initget "Bob Carol Ted Alice")

(command "bedit" "bvstate" "new" (getkword "\nSelect [Bob/Carol/Ted/Alice]: ") "h")

....

Kent Cooper, AIA
0 Likes
Message 3 of 10

Shneuph
Collaborator
Collaborator

I think the op means to simply type the name in at the command line.

 

I tried:

(command "bvstate" "new" pause "h")

 

 

It's making CAD Freeze up.  I don't know why.  Does this work for you?

 

EDIT: I only used command "bvstate"  Did not combine with "Bedit" as Kent did.

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
0 Likes
Message 4 of 10

Anonymous
Not applicable

By "allowable keywords" I assume you mean what I plan on naming the visibility state? If that is the case then when I have 100+ visibility states the "initget" line could become very long.

0 Likes
Message 5 of 10

Shneuph
Collaborator
Collaborator
Accepted solution

Try:

 

(command "bvstate" "new" (getstring T "\nEnter Visibility State Name:  ") "h")

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
0 Likes
Message 6 of 10

Anonymous
Not applicable

I think the op means to simply type the name in at the command line. Yes you are correct. If I add "initget" I will be adding 100+ words to this code.

 

I tried:

(command "bvstate" "new" pause "h") I also tried this and it caused CAD to freeze on me.

 

 

It's making CAD Freeze up.  I don't know why.  Does this work for you?

 

EDIT: I only used command "bvstate"  Did not combine with "Bedit" as Kent did. Im trying to combine all four commands into a step by step code that performs in sequence as one.

 

0 Likes
Message 7 of 10

Anonymous
Not applicable

Try:

 

(command "bvstate" "new" (getstring T "\nEnter Visibility State Name:  ") "h") Thank you! this works perfectly. Exactly what I needed. If you don't mind me asking where does the "T" after "Getstring" come from?

0 Likes
Message 8 of 10

Shneuph
Collaborator
Collaborator

Allows user to insert space:

 

 

https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2017/ENU/AutoCAD-MAC-AutoLISP-...

 

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
0 Likes
Message 9 of 10

Kent1Cooper
Consultant
Consultant

@Shneuph wrote:

.... 

EDIT: I only used command "bvstate"  Did not combine with "Bedit" as Kent did.


I only did that because of this in the original:

 

(command"bedit")

(command"bvstate""new" ....

 

More than one command can be combined into one (command) function.  But I am not familiar enough with visibility states, and generally prefer REFEDIT to BEDIT anyway, so if BVSTATE is not an option within  BEDIT, then combining them as I did won't work.  If BEDIT is something you need to do first, including User input(s) and finishing it before calling up BVSTATE, there needs to be something in there for accepting such User input(s).  But I'm not sure that can  be done with BEDIT in AutoLisp functions.  It doesn't seem to work to use the typical

 

(while (> (getvar 'cmdactive 0)) (command pause))

 

thing, and then move on to the next thing, at least it didn't for me in a quick trial.

Kent Cooper, AIA
0 Likes
Message 10 of 10

Anonymous
Not applicable

Thanks guys! It does exactly what I need now. Here is what it ended up being:

 

(Defun C:AD ()
  (command"bedit");opens block editor for selected dynamic block
  (command "bvstate" "new" (getstring T "\nEnter Visibility State Name:  ") "h");activates and prompts user to name new visibility state then hides all others
  (command"pasteclip""0,0");pastes new block into newly created state
  (command"bclose""s");closes block editor and saves changes
  (princ)
  )

 

 

0 Likes