![]() |
|
![]() |
|
![]() |
|
![]() |
Maybe this will work.
Code:(defun c:DEH (/ lPointList scl scl1 dt1 pnt pointsToList _:cmdecho _:doc) (defun *error* (msg) (setvar 'cmdecho _:cmdecho) (cond ((vl-position msg '("Function cancelled" "quit / exit abort" "console break" nil ) ) ) ((princ (strcat "\nError: " msg))) ) ;; Set undo mark end point (vla-endundomark _:doc) (princ) ) (defun pointsToList (/ ssPoints iCounter ePoint oPoint aAttributes vAttributes oPointTag sTag lPoints lCoord ) (setq ssPoints (ssget "X" '((0 . "INSERT") (2 . "POINT"))) iCounter 0 ) (repeat (sslength ssPoints) (if (and (setq ePoint (ssname ssPoints iCounter)) (setq oPoint (vlax-ename->vla-object ePoint)) (setq iCounter (1+ iCounter)) (= (vla-get-hasattributes oPoint) :vlax-true) (setq aAttributes (vla-getattributes oPoint)) (setq vAttributes (vlax-variant-value aAttributes)) (setq aAttributes (vlax-safearray->list vAttributes)) (setq oPointTag (car aAttributes)) (setq sTag (vla-get-textstring oPointTag)) (setq lCoord (vlax-safearray->list (vlax-variant-value (vla-get-insertionpoint oPoint)) ) ) ) (progn (setq lPoints (append lPoints (list (cons sTag (list oPoint lCoord))) ) ) ) ) ) lPoints ) ;; save reference to current doc (setq _:doc (vla-get-activedocument (vlax-get-acad-object))) (vla-startundomark _:doc) ;; Disable command echo (setq _:cmdecho (getvar 'cmdecho)) (setvar 'cmdecho 0) (setq lPointList (pointsToList) scl (getint "\n Set Scale (50,100,200,250,500,etc): ") scl1 (* scl 0.0025) ) (while (progn (initget 128) (setq dt1 (getpoint "\n Specify point to insert the block: ")) ) (progn (cond ((and (= 'STR (type dt1)) (setq pnt (assoc dt1 lPointList)) ) (setq pnt (caddr pnt)) ) ((/= 'STR (type dt1)) (setq pnt dt1) ) (t (setq pnt nil) ) ) (if pnt (command "_.insert" "DEH1" pnt scl1 scl1 0) (princ "\n ** Invalid number ** ") ) ) ) (*error* nil) )
Last edited by Opie; 2023-08-07 at 12:25 PM. Reason: tweaked per user request
If you have a technical question, please find the appropriate forum and ask it there.
You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
jUSt
Hi Opie, You did it ..it is working !!!!!
I want to ask two things, if it is possible
1) I test the code and I see that support only numbers. Sometimes I have letters and numbers for example k1,k2,s1 or 1N,3S .Is it possible to support them?
and
2)Is any way to merge these two codes in case to have an option
Insert point ? [point / number] ;<-- to give the point number (like your code) or to pick a point (like the first code)
The fist code
Code:(Defun c:DEH ( / dt1 ) (command "_layer" "_m" "DEH" "_c" "33" "" "") (setq olderr *error* *error* at_err) (setvar "blipmode" 0) (setq osm (getvar "osmode")) (setvar "cmdecho" 0) (setq scl (getint "\n Set Scale (50,100,200,250,500,etc) :")) (setq scl1 (* scl 0.0025)) (setq dt1 (getpoint "\n Select point to insert the block:")) (command "insert" "c:\\MBL\\DEH1.dwg" dt1 scl1 scl1 0) (setvar "cmdecho" 1) (setvar "blipmode" 1) (setvar "osmode" osm) (command "setvar" "clayer" "0") )
Opie code
Code:(defun c:DEH (/ lPointList scl scl1 dt1 pnt pointsToList) (defun pointsToList (/ ssPoints iCounter ePoint oPoint aAttributes vAttributes oPointTag sTag lPoints lCoord ) (setq ssPoints (ssget "X" '((0 . "INSERT") (2 . "POINT"))) iCounter 0 ) (repeat (sslength ssPoints) (if (and (setq ePoint (ssname ssPoints iCounter)) (setq oPoint (vlax-ename->vla-object ePoint)) (setq iCounter (1+ iCounter)) (= (vla-get-hasattributes oPoint) :vlax-true) (setq aAttributes (vla-getattributes oPoint)) (setq vAttributes (vlax-variant-value aAttributes)) (setq aAttributes (vlax-safearray->list vAttributes)) (setq oPointTag (car aAttributes)) (setq sTag (vla-get-textstring oPointTag)) (setq lCoord (vlax-safearray->list (vlax-variant-value (vla-get-insertionpoint oPoint)) ) ) ) (progn (setq lPoints (append lPoints (list (cons sTag (list oPoint lCoord))) ) ) ) ) ) lPoints ) (setq lPointList (pointsToList) scl (getint "\n Set Scale (50,100,200,250,500,etc): ") scl1 (* scl 0.0025) dt1 (getint "\n Specify point to insert the block: ") ) (while (and dt1 (setq pnt (assoc (itoa dt1) lPointList)) (setq pnt (caddr pnt)) ) (progn (command "_.insert" "c:\\topocad\\MBL\\Σύμβολα\\DEH1.dwg" pnt scl1 scl1 0) (setq dt1 (getint "\n Specify point to insert the block: ")) ) ) (princ) )
Last edited by mhy3sx.; 2023-08-01 at 08:50 AM.
Yes it is possible. However, your original code does not actually select a block insert. It requests from the user to select a point. The returned value from the getpoint function (specified in the original code) returns a 3 element list representing the coordinates the user has picked. To allow the user to either enter a point number/string or pick a point in the drawing, the code would need to allow arbitrary input.
To allow for a string instead of only a number, you would need to change the input to specify the point to either a getstring function or possibly the getpoint function if using the arbitrary input. I've revised my code above.
Last edited by Opie; 2023-08-07 at 12:12 PM.
If you have a technical question, please find the appropriate forum and ask it there.
You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
jUSt
Hi Opie, I find a bug in your code and i need help. If the block point exist in the drawing the code works fine, but some times I don't have points in my drawing and i need to insert a block and the code is not working (don;t insert block). Is any way to if the point block don't exist to let me insert the block (only by pick a point)?
for example by giving an optiion
Insert point ? [point / number]
if i select point , the code works and without the point block ..... for multi times
and
if I choose number to work by giving the point number (only if point block exist) ... for multi times
Thanks
If you have a technical question, please find the appropriate forum and ask it there.
You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
jUSt
Hi Opie.I test your new code and I have this error
Code:Error: bad argument type: lselsetp nil
Thanks
I am not receiving this error during my testing using a drawing that already contains the DEH block. What steps are you doing to have this error occur?
Have you determined what line of code is causing this?
If you have a technical question, please find the appropriate forum and ask it there.
You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
jUSt
I create a new drawing without any block inside. I want this code to work in every drawing . If the drawing have the point block inside to have the option to insert the block by point number , if there is not a point block then insert the deh block by picking point. That's why i ask to have an optiion
Insert point ? [point / number]
if pick point -> then pick point (multy times)
if pick number -> give point number (multy times)
In your code is all together
Thanks