Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News:
Home
Help
Login
Register
TheSwamp
»
Code Red
»
AutoLISP (Vanilla / Visual)
»
Topic:
Layer creation not working in if statement
« previous
next »
Print
Pages: [
1
] |
Go Down
Author
Topic: Layer creation not working in if statement (Read 2122 times)
0 Members and 1 Guest are viewing this topic.
Windsor
Mosquito
Posts: 14
Layer creation not working in if statement
«
on:
December 12, 2023, 11:16:42 AM »
I have an AutoLisp script which I have created to plot a crossed out box on a non printable guide layer, I have incorperated an if statement to check if this layer is already within the current drawing and if not to create it. However if the layer is not present the script doesn't work.
Is there a way to resolve this problem at all? (probably something I haven't noticed as of yet)
Code - Auto/Visual Lisp:
[Select]
; Creates box on unprintable guide layer which has a
; cross trough it to denote an unused area of the drawing
(
defun
c:UNUSED
(
/
P1 P2 P3 P4 Change
)
(
vl-load-com
)
(
setq
CL
(
getvar
"clayer"
)
)
;Checks if 1 - Guide layer is already in drawing, if not creates it
(
if
(
tblsearch
"layer"
"1 - Guide"
)
;Statement
(
)
;if true
(
command
"_.LAYER"
"M"
"1 - Guide"
"C"
"Magenta"
""
"P"
"N"
""
)
;if false
)
;Inputs
(
setq
P1
(
getpoint
"
\n
Specify First Point:"
)
P3
(
getpoint
"
\n
Specify Second Point:"
)
)
;Calculations
(
setq
P2
(
list
(
car
P3
)
(
cadr
P1
)
)
)
(
setq
P4
(
list
(
car
P1
)
(
cadr
P3
)
)
)
;Change to 1 - Guide function
(
defun
change
(
)
(
command
"_.change"
(
entlast
)
""
"p"
"LA"
"1 - Guide"
""
)
)
;Box Plot
(
Command
"PLINE"
P1 P2 P3 P4
"c"
)
(
change
)
(
command
"LINE"
P1 P3
""
)
(
change
)
(
command
"LINE"
P2 P4
""
)
(
change
)
(
setvar
"clayer"
CL
)
(
prompt
"
\n
\t
Box Created!"
)
(
princ
)
)
Is there also a method for having a real-time preview of the shape from the first point until the second (opposite corner) is clicked?
Logged
kdub_nz
Mesozoic keyThumper
SuperMod
Water Moccasin
Posts: 2140
class keyThumper<T>:ILazy<T>
Re: Layer creation not working in if statement
«
Reply #1 on:
December 12, 2023, 02:06:02 PM »
Have a look at
(getcorner pt [msg])
:
https://help.autodesk.com/view/ACDLT/2024/ENU/?guid=GUID-21BE8290-7F11-400B-AC39-62A110F07545
Logged
Called Kerry in my other life
Retired; but they dragged me back in !
I live at UTC + 13.00
---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.
Lee Mac
Seagull
Posts: 12914
London, England
WWW
Re: Layer creation not working in if statement
«
Reply #2 on:
December 12, 2023, 03:46:23 PM »
You're missing an extra enter in your command expression:
Code - Auto/Visual Lisp:
[Select]
(
command
"_.LAYER"
"M"
"1 - Guide"
"C"
"Magenta"
""
"P"
"N"
""
""
)
Logged
Lee Mac Programming
•
Twitter
•
Exchange App Store
Lee Mac
Seagull
Posts: 12914
London, England
WWW
Re: Layer creation not working in if statement
«
Reply #3 on:
December 12, 2023, 04:01:43 PM »
A few other points to note:
You can use
(if (not (tblsearch "layer" "1 - Guide"))
followed by your command expression to avoid the empty list forming the 'then' argument, to improve readability.
You should either disable OSMODE during the execution of the PLINE command or prefix the point input with "_non" point modifiers to avoid Object Snap affecting the supplied point input.
(vl-load-com)
is not required here as you are not using COM.
You could use entmake to create both the layer and the polyline & lines to automatically assign the layer and avoid having to assign it after the object has been created (it will also be much faster and will be immune to the effect of Object Snap), here is an example to help:
Code - Auto/Visual Lisp:
[Select]
(
defun
c:unused
(
/
lay ocs pt1 pt2 pt3 pt4
)
(
setq
lay
"1 - Guide"
)
;; Layer Name
(
if
(
and
(
setq
pt1
(
getpoint
"
\n
Specify 1st point: "
)
)
(
setq
pt3
(
(
if
(
zerop
(
getvar
'worlducs
)
)
getpoint
getcorner
)
pt1
"
\n
Specify opposite corner: "
)
)
)
(
progn
(
if
(
not
(
tblsearch
"layer"
lay
)
)
(
entmake
(
list
'
(
000 .
"LAYER"
)
'
(
100
.
"AcDbSymbolTableRecord"
)
'
(
100
.
"AcDbLayerTableRecord"
)
'
(
070 .
0
)
;; on/unlocked
'
(
062 .
6
)
;; magenta colour
'
(
290
.
0
)
;; non-plotting
(
cons
2
lay
)
)
)
)
(
setq
pt2
(
cons
(
car
pt3
)
(
cdr
pt1
)
)
pt4
(
cons
(
car
pt1
)
(
cdr
pt3
)
)
ocs
(
trans
'
(
0
0
1
)
1
0
t
)
)
(
entmake
(
list
'
(
000 .
"LWPOLYLINE"
)
'
(
100
.
"AcDbEntity"
)
'
(
100
.
"AcDbPolyline"
)
'
(
090 .
4
)
;; 4 vertices
'
(
070 .
1
)
;; closed
(
cons
008 lay
)
;; layer
(
cons
010
(
trans
pt1
1
ocs
)
)
(
cons
010
(
trans
pt2
1
ocs
)
)
(
cons
010
(
trans
pt3
1
ocs
)
)
(
cons
010
(
trans
pt4
1
ocs
)
)
(
cons
210
ocs
)
)
)
(
entmake
(
list
'
(
000 .
"LINE"
)
(
cons
008 lay
)
(
cons
010
(
trans
pt1
1
0
)
)
(
cons
011
(
trans
pt3
1
0
)
)
)
)
(
entmake
(
list
'
(
000 .
"LINE"
)
(
cons
008 lay
)
(
cons
010
(
trans
pt2
1
0
)
)
(
cons
011
(
trans
pt4
1
0
)
)
)
)
)
)
(
princ
)
)
Logged
Lee Mac Programming
•
Twitter
•
Exchange App Store
Windsor
Mosquito
Posts: 14
Re: Layer creation not working in if statement
«
Reply #4 on:
December 14, 2023, 09:01:12 AM »
Thanks Kdub for the link, good reference for attempting again in the fiture.
Thanks Lee, something I had completely overlooked in my original attempt. And Thanks for the rewrite, many good points which I wouldn't have even thought to attempt!
Logged
Lee Mac
Seagull
Posts: 12914
London, England
WWW
Re: Layer creation not working in if statement
«
Reply #5 on:
December 14, 2023, 06:00:38 PM »
You're most welcome Windsor, happy to help.
Logged
Lee Mac Programming
•
Twitter
•
Exchange App Store
Print
Pages: [
1
] |
Go Up
« previous
next »
TheSwamp
»
Code Red
»
AutoLISP (Vanilla / Visual)
»
Topic:
Layer creation not working in if statement