Jump to content

Recommended Posts

  • Replies 37
  • Created
  • Last Reply

Top Posters In This Topic

  • rlx

    11

  • CAD_Noob

    10

  • devitg

    5

  • Tharwat

    5

Top Posters In This Topic

Posted

Thank you all for the info. and thanks again to RLX for the code...very much appreciated.

Posted
Thank you all for the info. and thanks again to RLX for the code...very much appreciated.

 

you're quite welcome Cad_Noob.

 

gr. Rlx

Posted
Replace command-s with:

(if command-s
 command-s
 command
)

 

I've seen before this being used in some code, but wouldn't this be cleaner:

 

(cond (command-s) (vl-cmdf) (command))

 

Once Lee Mac gave me similar advice in one code, so this thought appeared.

Posted

vl-cmdf function must be the most efficient / working one in all time and what's more is that it returns T which is a bonus.

Posted
vl-cmdf function must be the most efficient / working one in all time and what's more is that it returns T which is a bonus.

 

I still follow your "old" advice to avoid command-calls wherever its possible, that the entmake/entmod/vla-add route is far more comfortable for me than any command-call ever. :)

 

I guess that the only command call I'm using in my codes now is for the "PLOT" command, that I'm planning to substitute with PlotToFile / PlotToDevice methods.

Although I work only in 2D (unlike marko_ribar - yes I know he's forced to use command-calls in his 3D workflow codes).

Posted
I still follow your "old" advice to avoid command-calls wherever its possible, that the entmake/entmod/vla-add route is far more comfortable for me than any command-call ever. :)

 

I guess that the only command call I'm using in my codes now is for the "PLOT" command, that I'm planning to substitute with PlotToFile / PlotToDevice methods.

Although I work only in 2D (unlike marko_ribar - yes I know he's forced to use command-calls in his 3D workflow codes).

 

 

Hi Grrr / Tharwat,

 

 

I try to avoid command calls too but sometimes command is just a much simpler and shorter code to write and to maintain. Had a few command issues with some of my programs which were solved by using command-s so it was kinda automatic I used this although when I wrote this during my break I did think about using vla-insertblock but decided just old school was simpler and quicker and better to understand. Maybe if my boss gives me longer breaks...

 

 

gr. Rlx

Posted
I still follow your "old" advice to avoid command-calls wherever its possible, that the entmake/entmod/vla-add route is far more comfortable for me than any command-call ever. :)

Entirely agreed, but I was clarifying the usage between the three functions and not recommending using these functions unless its needed, necessarily or forced to use as you mentioned earlier.

 

Hi Grrr / Tharwat,

I try to avoid command calls too but sometimes command is just a much simpler and shorter code to write and to maintain. Had a few command issues with some of my programs which were solved by using command-s so it was kinda automatic I used this although when I wrote this during my break I did think about using vla-insertblock but decided just old school was simpler and quicker and better to understand. Maybe if my boss gives me longer breaks...

 

gr. Rlx

Hi Rlx,

 

Using the vla-insertblock function is much better than command calls for many advantages as it is faster than command calls (if you have to repeat the process many times) and to avoid using System Variables such ATTREQ, ATTDIA and COMDECHO in this case.

 

Regards.

Posted
Entirely agreed, but I was clarifying the usage between the three functions and not recommending using these functions unless its needed, necessarily or forced to use as you mentioned earlier.

 

 

Hi Rlx,

 

Using the vla-insertblock function is much better than command calls for many advantages as it is faster than command calls (if you have to repeat the process many times) and to avoid using System Variables such ATTREQ, ATTDIA and COMDECHO in this case.

 

Regards.

 

 

Hi Tharwat

 

 

Well , if OP really wants to use vla-insertblock , something like this (just for educational purposes) would be needed:

 

 

(defun tst ( / acadObj actDoc modelSpace ent insertionPnt )
 ; or in one go : (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-acad-object)))
 (setq acadObj (vlax-get-acad-object))
 (setq actDoc (vla-get-ActiveDocument acadObj))
 (setq modelSpace (vla-get-ModelSpace actDoc))
 
 ; just for testing select an entitiy that has insertionpoint
 (setq ent (car (nentsel)))
 
 ; insertionPnt in RoomTag routine was first retrieved with (setq ip (cdr (assoc 10 (entget (caddr ss)))))
 ; but for vla-insertblock I need an array
 (setq insertionPnt (apply 'vlax-3d-point (cdr (assoc 10 (entget ent)))))
 (vla-InsertBlock modelSpace insertionPnt "Room_Tag" 1 1 1 0)
 ; clean desk police
 (mapcar
   '(lambda(x)
      (if (and (= 'vla-object (type x)) (not (vlax-object-released-p x)))
 (vlax-release-object x))(set (quote x) nil))
   (list actDoc modelSpace acadObj)
 )
)

I agree its more elegant and faster but its also a little more code.

 

 

gr. Rlx

Posted
I've seen before this being used in some code, but wouldn't this be cleaner:

 

(cond (command-s) (vl-cmdf) (command))

 

Once Lee Mac gave me similar advice in one code, so this thought appeared.

 

Looks good to me.

 

I try to avoid command calls whenever possible, and have not tested the performance of vl-cmdf vs. command-s so not sure which is better :) I guess vl-cmdf has better backward compatibility though.

Posted

Hi Rlx,

 

A few helpful points if you would like.

 

[color="purple"];; To get the block object of current space		;;
;; regardless if its Model or PaperSpace.		;;[/color]

(setq space (vla-get-block (vla-get-activelayout
                            (vla-get-activedocument (vlax-get-acad-object))
                            )
             )
     )

[color="purple"];; There is no need to convert the coordinates		;;
;; to safearray when you use vlax-invoke function	;;[/color]

(vlax-invoke space 'insertblock '(0. 0. 0.) "Room_Tag" 1 1 1 0)

[color="purple"];; Finally, also there is no need to release		;;
;; the vla-objects as you have deomstrated into		;;
;; your last example. Methinks.				;;[/color]

Posted

one more query if its not too much too ask...

will it be possible to input a block scale before selecting the MTEXT?

 

then the code will remember the last inputed scale to be use to other MTEXT selection unless the user input another scale...

Posted
vl-cmdf function must be the most efficient / working one in all time

 

Why?.......

 

Posted
one more query if its not too much too ask...

will it be possible to input a block scale before selecting the MTEXT?

 

then the code will remember the last inputed scale to be use to other MTEXT selection unless the user input another scale...

 

 

(defun c:RoomTag ( / p1 p2 ss tl ip bn old-att-req)
 (vl-load-com)
 (setq old-att-req (getvar "ATTREQ") *RTS* (Get_RoomTagScale))
 (princ "\n<<< Select Mtexts >>> ")
 (cond
   ((not (and (setq p1 (getpoint "\nSelect 1st corner :"))
       (setq p2 (getcorner p1 "\nSelect 2nd corner :"))))
    (princ "\nNothing selected"))
   ((not (setq ss (ssget "w" p1 p2 '((0 . "MTEXT"))))) (princ "\nNo Mtext's found"))
   ((not (= (sslength ss) 4)) (princ "\nYou must select 4 Mtext's"))
   ((not (tblsearch "block" (setq bn "Room_Tag"))) (princ "\nBlock 'Room_Tag' not present"))
   (t
     (setq ss (sss ss) tl (mapcar '(lambda (x) (cdr (assoc 1 (entget x)))) ss)
    ip (cdr (assoc 10 (entget (caddr ss)))))
     (setvar "ATTREQ" 0)(command "-insert" bn ip *RTS* *RTS* 0)
     (mapcar '(lambda (att val) (wai bn att val)) '("RM_TAG" "RM_VENT" "RM_NO." "RM_AREA") tl)
     (mapcar 'entdel ss)
     (if (setq ss (ssget "w" p1 p2 '((0 . "LWPOLYLINE"))))
(progn (entdel (ssname ss 0))(setq ss nil)))
     (setvar "ATTREQ" old-att-req)
   )
 )
)
(defun Get_RoomTagScale ()
 (setq *RTS* (cond ((getreal (strcat "\nEnter Scale <" (rtos (setq *RTS* (cond (*RTS*)(1.0))) 2 2) ">: ")))(*RTS*)))
)

Like described by Lee : http://www.lee-mac.com/promptwithdefault.html

 

 

Have a nice weekend

 

 

gr. Rlx

Posted
Entirely agreed, but I was clarifying the usage between the three functions and not recommending using these functions unless its needed, necessarily or forced to use as you mentioned earlier.

 

Yes, I see.. I just brought your old memory-advice here. :)

 

 

Hi Grrr / Tharwat,

 

I try to avoid command calls too but sometimes command is just a much simpler and shorter code to write and to maintain. Had a few command issues with some of my programs which were solved by using command-s so it was kinda automatic I used this although when I wrote this during my break I did think about using vla-insertblock but decided just old school was simpler and quicker and better to understand. Maybe if my boss gives me longer breaks...

 

gr. Rlx

 

Hi Rlx,

Don't get me wrong - I wasn't picking at your code, rather contributing with something to the command-call discussion, as I've read only the short replies (and not the codes posted here).

Posted
Yes, I see.. I just brought your old memory-advice here. :)

 

 

 

 

Hi Rlx,

Don't get me wrong - I wasn't picking at your code, rather contributing with something to the command-call discussion, as I've read only the short replies (and not the codes posted here).

 

don't worry Grrr , I didn't take it as criticism , en contraire, I'm fully aware of the different uses of command(-s)/vl-cmf pro's & cons , just wanted the code to be simple (kiss, keep it simple stupid) :D

 

Have a nice weekend!

 

Gr. Rlx

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...