TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: MSTG007 on March 20, 2017, 09:30:46 AM

Title: Creating Blocks and if they existing
Post by: MSTG007 on March 20, 2017, 09:30:46 AM
I am trying to understand how to create a simple block through the following command:

Code: [Select]
(command "-block" "STALL20" "0,0" "window" "-1.738,2.1322" "7.8114,-20.86" "")
If this block "STALL20" were to already exist in the drawing, how can I add the "yes" portion to code to replace the block.

I hope that makes sense what I am asking! lol. thanks again guys
Title: Re: Creating Blocks and if they existing
Post by: ronjonp on March 20, 2017, 09:36:49 AM
Code - Auto/Visual Lisp: [Select]
  1. (if (tblobjname "block" "STALL20")
  2.   "Yes"
  3.   "No"
  4. )
Title: Re: Creating Blocks and if they existing
Post by: MSTG007 on March 20, 2017, 09:48:02 AM
So basically like this:

Code: [Select]
(command "-block" "STALL20" (if (tblobjname "block" "Stall20") "Yes" "No" ) "0,0" "window" "-1.738,2.1322" "7.8114,-20.86" "")
It works! not sure if that is the right format how it needs to be shown! lol. But works! Thank you!
Title: Re: Creating Blocks and if they existing
Post by: Grrr1337 on March 20, 2017, 10:03:10 AM
So basically like this:

More like:
Code: [Select]
(setq bnm "STALL20")
(cond
  ( (tblsearch "BLOCK" bnm) (alert "\nBlock Already exist!") )
  (T (command "_.-BLOCK" bnm "0,0" "window" "-1.738,2.1322" "7.8114,-20.86" "") )
)
Title: Re: Creating Blocks and if they existing
Post by: MSTG007 on March 20, 2017, 10:03:43 AM
I got to plug this into the rest of the routine and now will not execute...

Code: [Select]
(defun c:test()
(setvar "expert" 1)
(command "-layer" "make" "C_PARKING_COUNT" "color" "191" "" "" "plot" "no plot" "" "")
(command "circle" "4.5,-10,0" "2")
(command "-layer" "make" "C_PVMT_STRIPING_PARKING" "color" "1" "" "")
(command "LINE" "0,0" "0,-20.0" "")
(command "zoom" "extents")
(command "-block" "STALL20" (if (tblobjname "block" "Stall20") "Yes" "No" ) "0,0" "window" "-1.738,2.1322" "7.8114,-20.86" "")
(command "_erase" "window" "-1.738,2.1322" "7.8114,-20.86" "")
(setvar "expert" 0)
)
(princ)
(C:test)

Command Prompt.

Code: [Select]
Command: (LOAD "C:/Users/rberger/Desktop/replace block demo.lsp") -layer
Current layer:  "0"
Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: make
Enter name for new layer (becomes the current layer) <0>: C_PARKING_COUNT Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: color
New color [Truecolor/COlorbook] : 191
Enter name list of layer(s) for color 191 <C_PARKING_COUNT>: Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]:
Command: plot Detailed plot configuration? [Yes/No] <No>: no plot
Command: _HELP
Command: _HELP
Command: circle
Specify center point for circle or [3P/2P/Ttr (tan tan radius)]: 4.5,-10,0
Specify radius of circle or [Diameter]: 2
Command: -layer
Current layer:  "C_PARKING_COUNT"
Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: make
Enter name for new layer (becomes the current layer) <C_PARKING_COUNT>: C_PVMT_STRIPING_PARKING Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: color
New color [Truecolor/COlorbook] : 1
Enter name list of layer(s) for color 1 (red) <C_PVMT_STRIPING_PARKING>: Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]:
Command: LINE
Specify first point: 0,0
Specify next point or [Undo]: 0,-20.0
Specify next point or [Undo]:
Command: zoom
Specify corner of window, enter a scale factor (nX or nXP), or
[All/Center/Dynamic/Extents/Previous/Scale/Window/Object] <real time>: extents Regenerating model.
Command: -block
Enter block name or [?]: STALL20 Specify insertion base point or [Annotative]: No
Point or option keyword required.
; error: Function cancelled
Specify insertion base point or [Annotative]:
Point or option keyword required.
Specify insertion base point or [Annotative]: *Cancel*
Command: *Cancel*



I gotta love Mondays. Sorry about this.
Title: Re: Creating Blocks and if they existing
Post by: MSTG007 on March 20, 2017, 10:15:27 AM
Thanks Grrr... Everything is working now. Again sorry for the blahhh lol !