| กก |
KozMos
provide some useful Visual LISP resource codes here, some of the
resource coming from internet and some are design by KozMos. Following
is the resource list:
LOCKUP:
Lock DWG by converting objects into MINSERT unnamed block
LOCKUP.LSP is posted to me from SPAUG by answering a question on protecting the DWG data. The design purpose of Lockup is to convert all objects into one MINSERT block, this is an unnamed minserted block, so common explode command will NOT explode it.
Lockup is very easy to UNLOCK. But it is still a good idea and utility to lock data to common (not expert) AutoCAD users.
Following is the source code of
LOCKUP.LSP:
Lockup.lsp - Locks all selected entities (except proxy objects) within a drawing.
By: John D. Chapman
With help from: Stig Madsen, Celie Dailey, Pat Starkey.
Based on and expanded from AB.lsp by Brian Debelius (Make/Insert an Anonymous Block)
and AB-Minsert.lsp by Rick McElvain (Make/MINSERT an Anonymous Block).
Inspiration from Adam Conrath (MINSERT).
Special mention to Jim Fisher.
Last Revisions:
March 05, 2002: Separate block made of solids before main routine runs.
March 07, 2002: Separate Block made of background colours (8,9,251-255).
March 22, 2002: Improved error trapping.
This routine turns on, thaws, and unlocks all layers before it starts the lock. The state of your layers prior to running LOCKUP will be restored in AutoCAD 200x only. |
View source codes of LOCKUP HERE!
XLock: Lock lines in DWG by converting them into space texts with underline
We have met the situation to provide real AutoCAD DWG files to our clients. But this may be dangerous in protection our drawing data. If any other one takes our DWG file, what they do may be only change some TEXT contents so that they would finish the design very similar with ours. This is NOT what we want.
If we can call this a problems, we may be confused by this for a long time. KozMos has tried many methods to transfer the drawing data from common objects into another entity types. (such as convert ARC/Circle into line segment, convert line into 3DFACE or TRACE or SOLID). All of these methods faced a common problem: the converted objects may be unlocked. And the convert procedure will cause a very long time, even got fatal errors on AutoCAD drawing data. Before XLOCK, we can only use AutoCAD WMFOUT and WMFIN to convert all objects into LWPolylines as the most simple solution on lock.
The design idea of XLOCK comes from an occasion situation. Based on the study of AutoCAD's TXT.SHX on spacebar underline location, KozMos developed XLOCK which will use a TEXT underline to substitute common line. By this conversion, the clients will lose the ability to get the two end points of "LINES". As another features, the clients will also fail to use AutoCAD common OFFSET/TRIM/EXTEND commands to modify the certain "LINES". This will REALLY make the further modification more hard and difficult. And it is the PROTECT clue of XLock.
The routine was enhanced to convert lines nested in block definition into text underline in one command and explode all complex entities such as dimension, mtext and mlines into more simple lines and texts so that the later processing will do more lines in order to make the drawing more complex.
As another interesting effects, command XL0 can remove all the TEXT underlines, the drawing will be very "EMPTY" without any lines, but it DO have data. Do you know how to open it? Run XL1, and you will get all lines appeared.
Press HERE to view source codes of
XLOCK.LSP.
AcDbTable:
Get the MTEXT entity name of picked AcDbTable cell
It is very hard to get the nested
MTEXT in AcDbTable. In fact, we even can not get the nest MTEXT object
because Autodesk did not provide us the way. So we MUST do this in a very
special way. We can use the NENTSELP or NENTSEL function and pick the MTEXT
object, then we can get the MTEXT object. It is absolutely unacceptable if we
have to pick the MTEXT each time, but we can call NENTSELP with an indicated
point without picking it.
Our special method to get the cell
content MTEXT object is based on the following conditions and steps:
- We can get the MTEXT content via AcDbTable's "GetText"
method;
- We can get the four boundary corner points of an
AcDbTable cell via AcDbTable's "GetCellExtent" method;
- By dividing the cell Length and Height into 10 parts,
we can build a 10x10 points list;
- Map the points list to (nentselp point) function to
see if we can get a return value.
- If there is a value returned (maybe a border line is
picked), check if it is a MTEXT with the same "TextString" as the AcDbTable cell content, if so, it is the MTEXT object we want to get.
Following is KozMos's real executive
Visual LISP codes to do so:
|
| กก |
Copyright (C) 1994-2009 by KozMos Inc.
Permission to use, copy, modify, and distribute this software
for any purpose and without fee is hereby granted, provided that
the above copyright notice appears in all copies and that both that
copyright notice and the limited warranty and restricted rights notice
below appear in all supporting documentation.
KOZMOS PROVIDES THIS PROGRAM "AS IS" AND WITH ALL
FAULTS. KOZMOS SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. KOZMOS INC. DOES NOT
WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE UNINTERRUPTED OR ERROR
FREE.(Defun
vltbl-get-cell-mtext (tbl row col / xsub-nentselp-mtext
xsub-divide-lists
str ptx p1 p2 p3 p4 dx dy dd px py vvv rtn)
(Defun xsub-nentselp-mtext (pt str / val rtn)
(if (and (setq val (nentselp pt))
(setq val (car
val))
(= (cdr (assoc 0
(entget val))) "MTEXT")
(= (vla-get-textstring
(vlax-ename->vla-object val)) str)
)
(setq rtn val)
)
rtn
)
(defun xsub-divide-lists (lst n / element item new)
(foreach element (reverse lst)
(setq item (cons element item))
(if (= (length item) n)
(setq new (cons item new) item nil)
)
)
new
)
(setq tbl (vlax-ename->vla-object tbl)
str (vlax-invoke-method tbl "GetText" row
col)
ptx (xsub-divide-lists
(vlax-safearray->list
(vlax-variant-value
(vla-getcellextents tbl row col 0)
)
)
3
)
)
(if (setq rtn (not (equal str "")))
(progn
(setq p1 (trans (nth 0
ptx) 0 1)
p2
(trans (nth 1 ptx) 0 1)
p3
(trans (nth 2 ptx) 0 1)
p4
(trans (nth 3 ptx) 0 1)
dd
(* 0.02 (distance p1 p4))
p1
(polar p1 (angle p1 p4) dd)
p4
(polar p4 (angle p4 p1) dd)
p2
(polar p2 (angle p2 p3) dd)
p3
(polar p3 (angle p3 p2) dd)
dx
(* 0.1 (abs (- (car p1) (car p2))))
dy
(* 0.1 (abs (- (cadr p1) (cadr p3))))
px
(car p1)
py
(cadr p1)
vvv nil
)
(repeat 10
(setq px (car p1))
(repeat 10
(setq vvv (cons (list px py)
vvv))
(setq px (+ px dx))
)
(setq py (- py dy))
)
(while vvv
(if (null (setq rtn (xsub-nentselp-mtext (car
vvv) str)))
(setq vvv (cdr vvv))
(setq vvv nil)
)
)
)
)
rtn
) |
| กก |
Please note that modify the cell content MTEXT object
may be ignored by AcDbTable's update. If we change the properties of the MTEXT object and ENTUPD
the parent AcDbTable object, our modification will take effects. But while
moving
or adjusting the AcDbTable, our modification will be lost. In fact, when our
modification is active, call vltbl-get-cell-mtext again will return NIL. Only after
AcDbTable ignored our change can the function catch the content MTEXT again (But
the entity name is not the same one last time we got).
Copy and Paste within
(different) AcDbTable(s)
We can use system Copy-Paste
operation to copy contents between AcDbTable(s). Following is the step
to do so:
- Select source cells range and then press Ctrl+C for
copy or Ctrl+X for Cut.
- Select a destination cells range in same or
different AcDbTable (Make sure that the destination and source range
have the same columns' number and rows' number).
- Press Ctrl+V to paste the AcDbTable data in
clipboard into destination cells range.
If merged cells in source range
can not match merged cells in destination range, the merged cells will
not be transferred. If the destination range are all single cells or
have the same merged cells information as source range, the merged cells
will be transferred.
If we call Ctrl+V in an empty area, a new AcDbTable will be created. |