I'm trying to create a block in a lsp routine, where the 'objects' are variables from earlier in the lsp.
For some reason I am unable to add code to my posts, however
variable 1 = BV_BODY
variable 2 = BV_BALL
command "_.-Block" FLG1 "0,0,0" BV_BODY BV_BALL ""
A block is created but only contains one of the 'objects'
I've tried different name for the variables, same result.
attached zip file is an extract showing a bit more detail.
SteveN
Re: create block
#2Hi Steve,
You must create a selection set then add the new entities/objects to this selection set.
Refer to this routine:
You must create a selection set then add the new entities/objects to this selection set.
Refer to this routine:
Code: Select all
(DEFUN C:CreateBlock ()
(setq blockName "NewBlockName")
(if (not (tblsearch "block" blockName))
(progn
(SETQ ss (SSADD))
(command "_circle" (list 5 5 0) 5)
(setq eLast (entlast))
(SSADD eLast ss)
(command "_line" (list 0 0 0) (list 10 10 0) "")
(setq eLast (entlast))
(SSADD eLast ss)
(command "_.-Block" blockName (list 5 5 0) ss "")
)
(alert (strcat "Existing the block " blockName " in this drawing.\nExit!"))
)
(princ))
Re: create block
#3Thanks QuanNguyen,
I already have code for the table search earlier in the code, so trimmed your code to:
Sorry, I keep getting ERROR 403 FORBIDDEN ..............................
Try again tomorrow.
I already have code for the table search earlier in the code, so trimmed your code to:
Sorry, I keep getting ERROR 403 FORBIDDEN ..............................
Try again tomorrow.
Re: create block
#4I already have code for the table search earlier in the code, so trimmed your code to:
Only the BALL moved, changing the order, ie BALL first then BODY or as above makes no difference.
This is the result:
.
.
SteveN
I've added a section of the lisp file to put it into perspective. The problem area is ate the end!
I added the 'move' line to check both items were in the selection set, FAIL!(setq ss (SSADD))
(ssadd BV_BODY ss)
(ssadd BV_BALL ss)
(command "MOVE" SS "" "0,0,0" "5000,0,0" "")
Only the BALL moved, changing the order, ie BALL first then BODY or as above makes no difference.
This is the result:
.
.
SteveN
I've added a section of the lisp file to put it into perspective. The problem area is ate the end!
- Attachments
-
- new 2.zip
- (3.37 KiB) Downloaded 197 times
Re: create block
#5I have just edited the lisp to only have BV_BODY in the selection set & again with just BV_BALL and in both cases only the BALL is moved!!!!
Re: create block
#6I managed to get this working, through a bit of a work-around.
I have 2 components that I wanted to add to a block for future insertions into the dwg.
So I created blocks of each component which were then individually inserted into the dwg and then added to the selection set.
From here I was able to create a new block of the combined blocks.
A bit of a faff but it works (see attached zip) it also bloats the drawing database/table.
Steve
I have 2 components that I wanted to add to a block for future insertions into the dwg.
So I created blocks of each component which were then individually inserted into the dwg and then added to the selection set.
From here I was able to create a new block of the combined blocks.
A bit of a faff but it works (see attached zip) it also bloats the drawing database/table.
Steve
- Attachments
-
- new 3.zip
- (1.53 KiB) Downloaded 198 times
Re: create block
#8Because the command "UNION" and "SUBTRACT" didn't create any NEW entity.
so the value of the variable of BV_BODY and BV_BALL is the same (the selection set has ONE entity only).
Code: Select all
; CREATE BALL & SUBTRACT BORE
(command "_sphere" (strcat "0," (rtos BCTR#) ",0") "D" BALOD# "")
(setq RTJFBV14 (entlast))
(command "_CYLINDER" (strcat "0," (rtos BCTR#) ",0") "D" "20.00" (+ 10.00 SPIGOT#))
(setq RTJFBV15 (entlast))
(command "_UNION" RTJFBV14 RTJFBV15 "")
(setq RTJFBV16 (entlast))
(command "_subtract" RTJFBV16 "" RTJFBV10 "")
(setq BV_BALL (entlast))
......
(command "union" RTJFBV3 RTJFBV4 RTJFBV13 "")
(setq BV_BODY (entlast))
Re: create block
#9Thanks QuanNguyen,
I'm confused, can you explain a bit more please.
If this:
does not create a new entity. WHY?
but this does:
I'm confused, can you explain a bit more please.
If this:
Code: Select all
(command "_subtract" RTJFBV16 "" RTJFBV10 "")
(setq BV_BALL (entlast))does not create a new entity
but this does:
Code: Select all
(command "_subtract" RTJFBV16 "" RTJFBV10 "")
(setq BV_BALL (entlast))
(command "_change" "L" "" "P" "C" "1" "") ;Red
(command "_ROTATE" BV_BALL "" (strcat "0," (rtos BCTR#) ",0") "15")
(setq BVBALL (entlast))
(command "_.-Block" (strcat FLG1 "-BALL") "Y" "0,0,0" BVBALL "")
Re: create block
#10Try to change the color of RTJFBV16 to green and RTJFBV10 to white, then run your code (below) again.
(command "_subtract" RTJFBV16 "" RTJFBV10 "")
(setq BV_BALL (entlast))
(command "_change" "L" "" "P" "C" "1" "") ;Red
(command "_ROTATE" BV_BALL "" (strcat "0," (rtos BCTR#) ",0") "15")
(setq BVBALL (entlast))
(command "_.-Block" (strcat FLG1 "-BALL") "Y" "0,0,0" BVBALL "")
(command "_subtract" RTJFBV16 "" RTJFBV10 "")
(setq BV_BALL (entlast))
(command "_change" "L" "" "P" "C" "1" "") ;Red
(command "_ROTATE" BV_BALL "" (strcat "0," (rtos BCTR#) ",0") "15")
(setq BVBALL (entlast))
(command "_.-Block" (strcat FLG1 "-BALL") "Y" "0,0,0" BVBALL "")
Re: create block
#11I'm not sure what I should be seeing?
Here is the code:
and here is the results:
From Right to Left applying one colour at a time, and finally the Block command.
Applying the block at each colour change has no obvious impact in the result.
Steve
Here is the code:
Code: Select all
; CREATE BALL & SUBTRACT BORE
(command "_sphere" (strcat "0," (rtos BCTR#) ",0") "D" BALOD# "")
(setq RTJFBV14 (entlast))
(command "_CYLINDER" (strcat "0," (rtos BCTR#) ",0") "D" HOD# (+ 35.00 SPIGOT#))
(setq RTJFBV15 (entlast))
(command "_UNION" RTJFBV14 RTJFBV15 "")
(setq RTJFBV16 (entlast))
(command "_change" RTJFBV16 "" "P" "C" "3" "") ;GREEN first colour applied
(command "_subtract" RTJFBV16 "" RTJFBV10 "")
(setq BV_BALL (entlast))
(command "_change" BV_BALL "" "P" "C" "1" "") ;Red second colour applied
(command "_ROTATE" BV_BALL "" (strcat "0," (rtos BCTR#) ",0") "15")
(setq BVBALL (entlast))
(command "_.-Block" (strcat FLG1 "-BALL") "Y" "0,0,0" BVBALL ""); finally block applied
Applying the block at each colour change has no obvious impact in the result.
Steve
Re: create block
#12Try to run this routine:
and see the window text
Code: Select all
(DEFUN C:LastEntityHandle ()
(setvar "cmdecho" 0)
(setq BMK# 0
BORE# 45
BL# -250
BCTR# 20
BALOD# 100
HOD# 30
SPIGOT# 150 )
; CREATE BALL & SUBTRACT BORE
(command "_Circle" (list 0 BMK# 0) "D" BORE# )
(setq RTJFBV9 (entlast)) ;body I/D 2
(command "_Extrude" RTJFBV9 "" BL# )
(setq RTJFBV10 (entlast)) ;body I/D 2
(command "_erase" RTJFBV9 "")
; ROTATE BODY O/D & I/Ds
(command "_ROTATE3D" RTJFBV10 "" "X" (list 0 BMK# 0) "270" )
; CREATE BALL & SUBTRACT BORE
(command "_sphere" (list 0 BCTR# 0) "D" BALOD# )
(setq RTJFBV14 (entlast))
(princ (strcat "\nEntity handle: " (cdr (assoc 5(entget RTJFBV14)))))
(command "_CYLINDER" (list 0 BCTR# 0) "D" HOD# (+ 35.00 SPIGOT#))
(setq RTJFBV15 (entlast))
(princ (strcat "\nEntity handle: " (cdr (assoc 5(entget RTJFBV15)))))
(command "_UNION" RTJFBV14 RTJFBV15 "")
(setq RTJFBV16 (entlast))
(princ (strcat "\nEntity handle: " (cdr (assoc 5(entget RTJFBV16)))))
(command "_change" RTJFBV16 "" "P" "C" "3" "") ;GREEN first colour applied
(command "_subtract" RTJFBV16 "" RTJFBV10 "")
(setq BV_BALL (entlast))
(princ (strcat "\nEntity handle: " (cdr (assoc 5(entget BV_BALL)))))
(command "_change" BV_BALL "" "P" "C" "1" "") ;Red second colour applied
;(command "_ROTATE" BV_BALL "" (strcat "0," (rtos BCTR#) ",0") "15")
(setq BVBALL (entlast))
(princ (strcat "\nEntity handle: " (cdr (assoc 5(entget BVBALL)))))
;(command "_.-Block" (strcat FLG1 "-BALL") "Y" "0,0,0" BVBALL ""); finally block applied
(command "_change" BVBALL "" "P" "C" "4" "")
(princ)
)
and see the window text
Re: create block
#13Morning QuanNguyen,
Thanks for your help.
I copied your code, I get the same as your text window, that 4 of the 5 entities have the same handle & hence are the same.
So is this the result of an error in my code?
SteveN
Thanks for your help.
I copied your code, I get the same as your text window, that 4 of the 5 entities have the same handle & hence are the same.
So is this the result of an error in my code?
SteveN