Author Topic: Creating Blocks and if they existing  (Read 201 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Water Moccasin
  • Posts: 2074
  • I can't remeber what I already asked! I need help!
Creating Blocks and if they existing
« 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
Autodesk Infrastructure Design Suite 2017

ronjonp

  • Needs a day job
  • Posts: 6401
Re: Creating Blocks and if they existing
« Reply #1 on: March 20, 2017, 09:36:49 am »
Code - Auto/Visual Lisp: [Select]
  1. (if (tblobjname "block" "STALL20")
  2.  "Yes"
  3.  "No"
  4. )

Windows 10 x64 - AutoCAD /C3D 2018

Custom Build PC

MSTG007

  • Water Moccasin
  • Posts: 2074
  • I can't remeber what I already asked! I need help!
Re: Creating Blocks and if they existing
« Reply #2 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!
Autodesk Infrastructure Design Suite 2017

Grrr1337

  • Bull Frog
  • Posts: 416
Re: Creating Blocks and if they existing
« Reply #3 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" "") )
)

MSTG007

  • Water Moccasin
  • Posts: 2074
  • I can't remeber what I already asked! I need help!
Re: Creating Blocks and if they existing
« Reply #4 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.
Autodesk Infrastructure Design Suite 2017

MSTG007

  • Water Moccasin
  • Posts: 2074
  • I can't remeber what I already asked! I need help!
Re: Creating Blocks and if they existing
« Reply #5 on: March 20, 2017, 10:15:27 am »
Thanks Grrr... Everything is working now. Again sorry for the blahhh lol !
Autodesk Infrastructure Design Suite 2017