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:
Help with double offset and hatch lisp
« previous
next »
Print
Pages: [
1
] |
Go Down
Author
Topic: Help with double offset and hatch lisp (Read 1798 times)
0 Members and 1 Guest are viewing this topic.
PM
Guest
Help with double offset and hatch lisp
«
on:
May 21, 2021, 03:46:01 AM »
Hi . This code begin with an option .Double offset (0.5 -0.5) and (2.0 -2.0). I try to write it as (a -a) , i dont know if is wrong.
Then i want to select the layer 1 polylines and add a hatch between of then . The hatch must be in Layer1 with lw 0.05 and type ANSI31 with scale 0.1
The code is
Code - Auto/Visual Lisp:
[Select]
(
defun
c:test
(
/
a sel int ent
)
(
TEXTPAGE
)
(
princ
"
\n
"
)
(
princ
"
\n
"
)
(
princ
"
\n
"
)
(
progn
(
initget
"1 2"
)
(
setq
l
(
cond
(
(
getkword
"
\n
SELECT OFFSET:
1. OFFSET 0.5
2. OFFSET 2.0
"
)
)
(
"1"
)
)
)
(
if
(
eq
l
"1"
)
(
setq
a
0.5
)
)
(
if
(
eq
l
"2"
)
(
setq
a
2.0
)
)
)
(
COMMAND
"_layer"
"_m"
"LAYER1"
"_c"
"93"
""
"_lw"
"0.30"
""
""
)
(
and
(
or
(
tblsearch
"LAYER"
"LAYER2"
)
(
alert
"Layer name < LAYER2 > was not found in this drawing to continue!"
)
)
(
princ
"
\n
Select polygon <LAYER2 > to offset on two sides: "
)
(
setq
int
-
1
sel
(
ssget
"_X"
'
(
(
0
.
"LINE,*POLYLINE"
)
(
8
.
"LAYER2"
)
)
)
)
(
while
(
setq
int
(
1+
int
)
ent
(
ssname
sel int
)
)
(
foreach
off '
(
a
-
a
)
(
vla-put-layer
(
car
(
vlax-invoke
(
vlax
-
ename
->
vla-object
ent
)
'offset off
)
)
"LAYER1"
)
)
)
(
princ
)
)
(
vl-load-com
)
)
Can any one help ?
Thanks
«
Last Edit: May 21, 2021, 10:09:52 AM by PM
»
Logged
kpblc
Bull Frog
Posts: 396
Re: Help with double offset and hatch lisp
«
Reply #1 on:
May 21, 2021, 03:52:40 AM »
Change
Code - Auto/Visual Lisp:
[Select]
(
foreach
off '
(
a
-
a
)
to
Code - Auto/Visual Lisp:
[Select]
(
foreach
off
(
list
a
-
a
)
Logged
Sorry for my English.
PM
Guest
Re: Help with double offset and hatch lisp
«
Reply #2 on:
May 21, 2021, 10:02:37 AM »
Hi kpblc. I did the change but the code is not working as double offset but only like one side offset. The other problem is how to add hatch inside the double offset.
Code - Auto/Visual Lisp:
[Select]
(
defun
c:test
(
/
a sel int ent
)
(
TEXTPAGE
)
(
princ
"
\n
"
)
(
princ
"
\n
"
)
(
princ
"
\n
"
)
(
progn
(
initget
"1 2"
)
(
setq
l
(
cond
(
(
getkword
"
\n
SELECT OFFSET:
1. OFFSET 0.5
2. OFFSET 2.0
"
)
)
(
"1"
)
)
)
(
if
(
eq
l
"1"
)
(
setq
a
0.5
)
)
(
if
(
eq
l
"2"
)
(
setq
a
2.0
)
)
)
(
COMMAND
"_layer"
"_m"
"LAYER1"
"_c"
"93"
""
"_lw"
"0.30"
""
""
)
(
and
(
or
(
tblsearch
"LAYER"
"LAYER2"
)
(
alert
"Layer name < LAYER2 > was not found in this drawing to continue!"
)
)
(
princ
"
\n
Select polygon < LAYER2 > to offset on two sides: "
)
(
setq
int
-
1
sel
(
ssget
"_X"
'
(
(
0
.
"LINE,*POLYLINE"
)
(
8
.
"LAYER2"
)
)
)
)
(
while
(
setq
int
(
1+
int
)
ent
(
ssname
sel int
)
)
(
foreach
off
(
list
a
-
a
)
(
vla-put-layer
(
car
(
vlax-invoke
(
vlax
-
ename
->
vla-object
ent
)
'offset off
)
)
"LAYER1"
)
)
)
(
princ
)
)
(
vl-load-com
)
)
;end defun
Any options
??
Thanks
«
Last Edit: May 21, 2021, 10:27:38 AM by PM
»
Logged
PM
Guest
Re: Help with double offset and hatch lisp
«
Reply #3 on:
May 21, 2021, 11:02:15 AM »
I did a stupid solution but i dont know how to add the hatch
Code - Auto/Visual Lisp:
[Select]
(
defun
c:test
(
/
a sel int ent
)
(
TEXTPAGE
)
(
princ
"
\n
"
)
(
princ
"
\n
"
)
(
princ
"
\n
"
)
(
progn
(
initget
"1 2"
)
(
setq
l
(
cond
(
(
getkword
"
\n
SELECT OFFSET:
1. OFFSET 0.5
2. OFFSET 2.0
"
)
)
(
"1"
)
)
)
(
if
(
eq
l
"1"
)
(
c:test1
)
)
(
if
(
eq
l
"2"
)
(
c:test2
)
)
(
princ
)
)
(
vl-load-com
)
)
;end defun
(
defun
c:test1
(
/
a sel int ent
)
(
COMMAND
"_layer"
"_m"
"LAYER1"
"_c"
"93"
""
"_lw"
"0.30"
""
""
)
(
and
(
or
(
tblsearch
"LAYER"
"LAYER2"
)
(
alert
"Layer name < LAYER2 > was not found in this drawing to continue!"
)
)
(
princ
"
\n
Select polygon < LAYER2 > to offset on two sides: "
)
(
setq
int
-
1
sel
(
ssget
"_X"
'
(
(
0
.
"LINE,*POLYLINE"
)
(
8
.
"LAYER2"
)
)
)
)
(
while
(
setq
int
(
1+
int
)
ent
(
ssname
sel int
)
)
(
foreach
off '
(
0.5
-
0.5
)
(
vla-put-layer
(
car
(
vlax-invoke
(
vlax
-
ename
->
vla-object
ent
)
'offset off
)
)
"LAYER1"
)
)
)
(
princ
)
)
(
vl-load-com
)
)
;end defun
(
defun
c:test2
(
/
a sel int ent
)
(
COMMAND
"_layer"
"_m"
"LAYER1"
"_c"
"93"
""
"_lw"
"0.30"
""
""
)
(
and
(
or
(
tblsearch
"LAYER"
"LAYER2"
)
(
alert
"Layer name < LAYER2 > was not found in this drawing to continue!"
)
)
(
princ
"
\n
Select polygon < LAYER2 > to offset on two sides: "
)
(
setq
int
-
1
sel
(
ssget
"_X"
'
(
(
0
.
"LINE,*POLYLINE"
)
(
8
.
"LAYER2"
)
)
)
)
(
while
(
setq
int
(
1+
int
)
ent
(
ssname
sel int
)
)
(
foreach
off '
(
2.00
-
2.00
)
(
vla-put-layer
(
car
(
vlax-invoke
(
vlax
-
ename
->
vla-object
ent
)
'offset off
)
)
"LAYER1"
)
)
)
(
princ
)
)
(
vl-load-com
)
)
;end defun
Logged
kpblc
Bull Frog
Posts: 396
Re: Help with double offset and hatch lisp
«
Reply #4 on:
May 21, 2021, 01:31:54 PM »
Code - Auto/Visual Lisp:
[Select]
(
vl-load-com
)
(
defun
t1
(
/
selset offset_value loops hatch layer
)
(
if
(
and
(
=
(
type
(
setq
selset
(
vl
-
catch
-
all
-
apply
(
function
(
lambda
(
)
(
ssget
'
(
(
0
.
"*POLYLINE"
)
(
8
.
"layer2"
)
(
-
4
.
"<OR"
)
(
70
.
1
)
(
70
.
129
)
(
-
4
.
"OR>"
)
)
)
)
;_ end of lambda
)
;_ end of function
)
;_ end of vl-catch-all-apply
)
;_ end of setq
)
;_ end of type
'pickset
)
;_ end of =
(
=
(
type
(
setq
offset_value
(
vl
-
catch
-
all
-
apply
(
function
(
lambda
(
)
(
initget
"1 2"
)
(
cond
(
(
getkword
"
\n
Select offset value [1 - offset 0.5/2 - ossfet 2.0] <1> : "
)
)
(
t
"1"
)
)
;_ end of cond
)
;_ end of lambda
)
;_ end of function
)
;_ end of vl-catch-all-apply
)
;_ end of setq
)
;_ end of type
'str
)
;_ end of =
)
;_ end of and
(
progn
(
vla-startundomark
(
setq
adoc
(
vla-get-activedocument
(
vlax-get-acad-object
)
)
)
)
(
setq
layer
(
vla-add
(
vla-get-layers
adoc
)
"Layer1"
)
)
(
vla-put-color
layer
93
)
(
vla-put-lineweight
layer aclnwt030
)
(
setq
offset_value
(
cond
(
(
=
(
atoi
offset_value
)
1
)
0.5
)
(
(
=
(
atoi
offset_value
)
2
)
2.0
)
)
;_ end of cond
loops
(
mapcar
(
function
(
lambda
(
ent
)
(
vl-sort
(
mapcar
(
function
(
lambda
(
x
)
(
setq
x
(
car
(
vlax
-
safearray
->
list
(
vlax
-
variant-value
x
)
)
)
)
(
vla-put-layer
x
(
vla-get-name
layer
)
)
x
)
;_ end of lambda
)
;_ end of function
(
list
(
vla-offset
(
vlax
-
ename
->
vla-object
ent
)
offset_value
)
(
vla-offset
(
vlax
-
ename
->
vla-object
ent
)
(
-
offset_value
)
)
)
;_ end of list
)
;_ end of mapcar
(
function
(
lambda
(
a b
)
(
>
(
vla-get-area
a
)
(
vla-get-area
b
)
)
)
)
)
;_ end of vl-sort
)
;_ end of lambda
)
;_ end of function
(
(
lambda
(
/
tab item
)
(
repeat
(
setq
tab
nil
item
(
sslength
selset
)
)
;_ end setq
(
setq
tab
(
cons
(
ssname
selset
(
setq
item
(
1-
item
)
)
)
tab
)
)
)
;_ end of repeat
)
;_ end of lambda
)
)
;_ end of mapcar
)
;_ end of setq
(
foreach
item loops
(
setq
hatch
(
vla-addhatch
(
vla-get-modelspace
adoc
)
achatchpatterntypepredefined
"ANSI31"
:vlax-false
achatchobject
)
;_ end of vla-AddHatch
)
;_ end of setq
(
vla-appendouterloop
hatch
(
vlax-safearray-fill
(
vlax
-
make
-
safearray
vlax-vbobject
'
(
0
.
0
)
)
(
list
(
car
item
)
)
)
)
;_ end of vla-appendouterloop
(
vla-appendinnerloop
hatch
(
vlax-safearray-fill
(
vlax
-
make
-
safearray
vlax-vbobject
'
(
0
.
0
)
)
(
list
(
cadr
item
)
)
)
)
;_ end of vla-appendinnerloop
(
vla-evaluate
hatch
)
(
vla-update
hatch
)
(
vla-put-layer
hatch
(
vla-get-name
layer
)
)
)
;_ end of foreach
(
vla-endundomark
adoc
)
)
;_ end of progn
)
;_ end of if
(
princ
)
)
;_ end of defun
Logged
Sorry for my English.
PM
Guest
Re: Help with double offset and hatch lisp
«
Reply #5 on:
May 21, 2021, 03:26:42 PM »
Thank you kpblc
Logged
PM
Guest
Re: Help with double offset and hatch lisp
«
Reply #6 on:
May 21, 2021, 03:54:49 PM »
Hi kpblc a last question. How to change pattetn scale to 0.1 and hatch linetype bylayer ?
Thanks
«
Last Edit: May 21, 2021, 03:58:07 PM by PM
»
Logged
PM
Guest
Re: Help with double offset and hatch lisp
«
Reply #7 on:
May 22, 2021, 02:37:23 AM »
Thans
kpblc
i fix it
Logged
Lee Mac
Seagull
Posts: 12913
London, England
WWW
Re: Help with double offset and hatch lisp
«
Reply #8 on:
May 22, 2021, 09:58:47 AM »
Another, from almost 10 years ago...
https://www.cadtutor.net/forum/topic/43291-hatch-of-closed-polylines-offset-from-user-designated-points/?tab=comments#comment-353466
Logged
Lee Mac Programming
•
Twitter
•
Exchange App Store
ScottMC
Newt
Posts: 191
Re: Help with double offset and hatch lisp
«
Reply #9 on:
May 23, 2021, 06:33:03 PM »
Just tried it and VLIDE'd to understand the oops.. NOT yet
Corrected by removing: 103, 106, 132,133,134 and adding
(command "-bhatch" "S" "L" "" "") at the end. oldies still work!
Thanks Much Lee - you keep me thinkin
«
Last Edit: May 23, 2021, 11:05:46 PM by ScottMC
»
Logged
Print
Pages: [
1
] |
Go Up
« previous
next »
TheSwamp
»
Code Red
»
AutoLISP (Vanilla / Visual)
»
Topic:
Help with double offset and hatch lisp