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:
Find known object inside a block
« previous
next »
Print
Pages: [
1
] |
Go Down
Author
Topic: Find known object inside a block (Read 1548 times)
0 Members and 1 Guest are viewing this topic.
kenkrupa
Newt
Posts: 84
WWW
Find known object inside a block
«
on:
November 27, 2013, 03:27:29 PM »
Some dynamic blocks each contain a circle. For any insertion of that block, I want to find the center point of that circle. It will always lie in the World plane, but it's relation to the insertion point varies when a dynamic angle changes. I need to find the center of this circle. Any way to do this?
Logged
Lee Mac
Seagull
Posts: 12929
London, England
WWW
Re: Find known object inside a block
«
Reply #1 on:
November 27, 2013, 06:48:57 PM »
You should be able to use the center of the circle found within the anonymous block definition that is automatically generated for the dynamic block reference when the dynamic parameters are altered.
You would then transform the center coordinates to account for the block reference position, scale & rotation using an appropriate transformation matrix - for this I would recommend gile's
refgeom
function.
Logged
Lee Mac Programming
•
Twitter
•
Exchange App Store
kenkrupa
Newt
Posts: 84
WWW
Re: Find known object inside a block
«
Reply #2 on:
November 27, 2013, 10:22:16 PM »
Thank you much Lee, and gile too. That matrix stuff is something I would never figure out myself. Going into Thanksgiving day here, so it may be a few days before I can apply this, but I'm thankful for it already!
Logged
Lee Mac
Seagull
Posts: 12929
London, England
WWW
Re: Find known object inside a block
«
Reply #3 on:
November 28, 2013, 09:38:29 AM »
You're most welcome ken
Here is a quick & simple example program for you to test:
Code - Auto/Visual Lisp:
[Select]
(
defun
c:cc
(
/
blk bln blx cen ent enx lst
)
(
while
(
progn
(
setvar
'errno
0
)
(
setq
blk
(
car
(
entsel
"
\n
Select block: "
)
)
cen
nil
)
(
cond
(
(
=
7
(
getvar
'errno
)
)
(
princ
"
\n
Missed, try again."
)
)
(
(
null
blk
)
nil
)
(
(
/=
"INSERT"
(
cdr
(
assoc
0
(
setq
blx
(
entget
blk
)
)
)
)
)
(
princ
"
\n
Please select a block."
)
)
(
(
not
(
or
(
setq
bln
(
cdr
(
assoc
2
blx
)
)
cen
(
cdr
(
assoc
bln lst
)
)
)
(
progn
(
setq
ent
(
tblobjname
"block"
bln
)
)
(
while
(
and
(
null
cen
)
(
setq
ent
(
entnext
ent
)
)
)
(
if
(
=
"CIRCLE"
(
cdr
(
assoc
0
(
setq
enx
(
entget
ent
)
)
)
)
)
(
setq
cen
(
trans
(
cdr
(
assoc
10
enx
)
)
(
cdr
(
assoc
210
enx
)
)
0
)
)
)
)
(
if
cen
(
setq
lst
(
cons
(
cons
bln cen
)
lst
)
)
)
)
)
)
(
princ
"
\n
Selected block does not contain a circle."
)
)
(
(
entmake
(
list
'
(
0
.
"POINT"
)
(
cons
10
(
apply
'
(
lambda
(
m v
)
(
mapcar
'
+
(
mxv m cen
)
v
)
)
(
refgeom blk
)
)
)
)
)
)
)
)
)
(
princ
)
)
;; RefGeom (gile)
;; Returns a list whose first item is a 3x3 transformation matrix and
;; second item the object insertion point in its parent (xref, block or space)
(
defun
refgeom
(
ent
/
ang enx mat ocs
)
(
setq
enx
(
entget
ent
)
ang
(
cdr
(
assoc
050 enx
)
)
ocs
(
cdr
(
assoc
210
enx
)
)
)
(
list
(
setq
mat
(
mxm
(
mapcar
'
(
lambda
(
v
)
(
trans
v
0
ocs t
)
)
'
(
(
1.0
0.0
0.0
)
(
0.0
1.0
0.0
)
(
0.0
0.0
1.0
)
)
)
(
mxm
(
list
(
list
(
cos
ang
)
(
-
(
sin
ang
)
)
0.0
)
(
list
(
sin
ang
)
(
cos
ang
)
0.0
)
'
(
0.0
0.0
1.0
)
)
(
list
(
list
(
cdr
(
assoc
41
enx
)
)
0.0
0.0
)
(
list
0.0
(
cdr
(
assoc
42
enx
)
)
0.0
)
(
list
0.0
0.0
(
cdr
(
assoc
43
enx
)
)
)
)
)
)
)
(
mapcar
'
-
(
trans
(
cdr
(
assoc
10
enx
)
)
ocs
0
)
(
mxv mat
(
cdr
(
assoc
10
(
tblsearch
"block"
(
cdr
(
assoc
2
enx
)
)
)
)
)
)
)
)
)
;; Matrix Transpose - Doug Wilson
;; Args: m - nxn matrix
(
defun
trp
(
m
)
(
apply
'
mapcar
(
cons
'
list
m
)
)
)
;; Matrix x Matrix - Vladimir Nesterovsky
;; Args: m,n - nxn matrices
(
defun
mxm
(
m n
)
(
(
lambda
(
a
)
(
mapcar
'
(
lambda
(
r
)
(
mxv a r
)
)
m
)
)
(
trp n
)
)
)
;; Matrix x Vector - Vladimir Nesterovsky
;; Args: m - nxn matrix, v - vector in R^n
(
defun
mxv
(
m v
)
(
mapcar
'
(
lambda
(
r
)
(
apply
'
+
(
mapcar
'
*
r v
)
)
)
m
)
)
(
princ
)
The program will generate a
POINT
entity at the center of the first circle found in the block definition (this could easily be altered to match circles based on criteria such as layer / linetype / colour / handle etc.)
Here is a demonstration using a simple dynamic block with a dynamic move parameter assigned to the circle:
«
Last Edit: November 28, 2013, 09:41:34 AM by Lee Mac
»
Logged
Lee Mac Programming
•
Twitter
•
Exchange App Store
kenkrupa
Newt
Posts: 84
WWW
Re: Find known object inside a block
«
Reply #4 on:
November 28, 2013, 10:35:31 AM »
Perfect! Thank you!
Logged
Print
Pages: [
1
] |
Go Up
« previous
next »
TheSwamp
»
Code Red
»
AutoLISP (Vanilla / Visual)
»
Topic:
Find known object inside a block