Jump to content

Begin line at block insertion point


stevesfr

Recommended Posts

Greetings:

In the earlier years of Acad it was possible to rename certain unused F-keys. In those years I assigned a command for a short lisp to an F-key.

For example, upon entering LINE at the command line, one could hit the respective F-key (which contained the command for the short lisp) and the line would commence at the block insertion point if you picked anywhere on the block or its respective attributes. Now I would like to either know how to rename a useless F-key or combine my little lisp into another lisp, to that it would start the line at the insertion point of a picked block or its respective attribute(s).

Cheers

S

Link to comment
Share on other sites

  • Replies 62
  • Created
  • Last Reply

Top Posters In This Topic

  • alanjt

    29

  • Lee Mac

    12

  • stevesfr

    11

  • Demesne

    6

Top Posters In This Topic

Posted Images

You could call a LISP like this transparently:

 

(defun c:AtInsertion ( / obj )
 (if
   (setq obj
      (SelectifFoo
        (lambda ( x / o )
          (setq o
            (vlax-ename->vla-object
              (cond
                (
                  (= (length x) 4) (car (last x))
                )
                (
                  (car x)
                )
              )
            )
          )
          (if (vlax-property-available-p o 'InsertionPoint)
            o
          )
        )
        "\nSelect Object: "
      )
    )
   (vlax-get obj 'InsertionPoint)
 )
)

(defun SelectifFoo ( foo str / sel x )
 (while
   (progn
     (setq sel (nentsel str))
     
     (cond
       (
         (vl-consp sel)

         (if (not (setq x (foo sel)))
           (princ "\n** Invalid Object Selected **")
         )
       )
     )
   )
 )
 x
)

_non 'AtInsertion

Link to comment
Share on other sites

You could call a LISP like this transparently:

 

(defun c:AtInsertion ( / obj )
 (if
   (setq obj
      (SelectifFoo
        (lambda ( x / o )
          (setq o
            (vlax-ename->vla-object
              (cond
                (
                  (= (length x) 4) (car (last x))
                )
                (
                  (car x)
                )
              )
            )
          )
          (if (vlax-property-available-p o 'InsertionPoint)
            o
          )
        )
        "\nSelect Object: "
      )
    )
   (vlax-get obj 'InsertionPoint)
 )
)

(defun SelectifFoo ( foo str / sel x )
 (while
   (progn
     (setq sel (nentsel str))

     (cond
       (
         (vl-consp sel)

         (if (not (setq x (foo sel)))
           (princ "\n** Invalid Object Selected **")
         )
       )
     )
   )
 )
 x
)

_non 'AtInsertion

 

Lee, this is what is happening here:

If a block is picked, the line begins at the block insertion point. If an attribute of a block is picked, the line begins at the pick point.

 

The following is the lisp I used to use:

 

 
;get insertion point of BLOCK by picking any attribute !
; 
(DEFUN VV (/ PT1 PT2 PT5 PT6)
   (SETQ PT1 (ENTSEL "\nPick on BLOCK or ATTRIBUTE: "))
   (SETQ ENT(ENTGET (CAR PT1)))
   (SETQ PT5 (CDR (ASSOC 10 ENT)))
)

 

If you load this lisp, and after entering the line command, enter (VV) and pick the respective attribute, the line will begin at the block insertion point. This is very handy way of finding the block insertion point where there are many many point blocks clustered together with attributes of point#, desc, and elevations etc.

Hope this is more informative for you.

Cheers

S

Link to comment
Share on other sites

From the description you gave, I was under the impression that you wanted to use the attribute insertion if the attribute was picked... :unsure:

Link to comment
Share on other sites

From the description you gave, I was under the impression that you wanted to use the attribute insertion if the attribute was picked... :unsure:

 

Lee: your interpretation was correct. My bad. The last sentence should have read... line starts at the insertion point of the block wether the block or its attribute are picked.

Sorry to all !

S

Link to comment
Share on other sites

No worries - you had the code already, but this may be better:

 

(defun c:AtInsertion ( / obj )
 (if
   (setq obj
     (SelectifFoo
       (lambda ( x )
         (if
           (vlax-property-available-p
             (setq x (vlax-ename->vla-object x)) 'InsertionPoint
           )
           x
         )
       )
       "\nSelect Object: "
     )
   )
   (trans (vlax-get obj 'InsertionPoint) (vlax-get obj 'Normal) 1)
 )
)

(defun SelectifFoo ( foo str / sel x )
 (while
   (progn
     (setq sel (entsel str))
     
     (cond
       (
         (vl-consp sel)

         (if (not (setq x (foo (car sel))))
           (princ "\n** Invalid Object Selected **")
         )
       )
     )
   )
 )
 x
)

Link to comment
Share on other sites

Don't forget to translate your point to UCS. Very nice code Lee. :)

 

Something else to play with...

 

(defun c:AI (/ ss)
 (if (setq ss (ssget "_+.:E:S" '((0 . "INSERT"))))
   ((lambda (ins)
      (if (eq 1 (logand 1 (getvar 'cmdactive)))
        ins
        (command "_.line" "_non" ins)
      )
    )
     (trans (cdr (assoc 10 (entget (ssname ss 0)))) 0 1)
   )
 )
)

Link to comment
Share on other sites

Oh yeah, you can edit the F-keys in the CUI editor (called Accelerator Keys), but the easiest way is to just create an MNU file and load them from there. Also, if you use an MNL startup file with the same name as the MNU, it will automatically load on each startup.

 

Here's clip from my AlanThompson.mnu file:

***MENUGROUP=[color=Red]AlanThompson[/color]

***TOOLBARS

***ACCELERATORS
["F1"]^C^CEXCHPROP
["F4"]^C^CIMPORTLAYERS
["F5"]^C^CPEDIT _M
["F6"]^C^CM2P
["F7"]^C^C'MATH
[CONTROL+"Z"]'_zoom _p

 

I load all my lisp routines and settings through a filed called AlanThompson.mnl

 

When I get a new computer, all I have to do is type MenuLoad, load my AlanThompson.mnu file and I'm good to go.

 

FYI, be sure to change the MENUGROUP name (colored in red).

Link to comment
Share on other sites

Oh yeah, you can edit the F-keys in the CUI editor (called Accelerator Keys), but the easiest way is to just create an MNU file and load them from there. Also, if you use an MNL startup file with the same name as the MNU, it will automatically load on each startup.

 

Here's clip from my AlanThompson.mnu file:

***MENUGROUP=[color=red]AlanThompson[/color]

***TOOLBARS

***ACCELERATORS
["F1"]^C^CEXCHPROP
["F4"]^C^CIMPORTLAYERS
["F5"]^C^CPEDIT _M
["F6"]^C^CM2P
["F7"]^C^C'MATH
[CONTROL+"Z"]'_zoom _p

 

I load all my lisp routines and settings through a filed called AlanThompson.mnl

 

When I get a new computer, all I have to do is type MenuLoad, load my AlanThompson.mnu file and I'm good to go.

 

FYI, be sure to change the MENUGROUP name (colored in red).

 

 

Thanks Alan and Lee, I'm off to ponder.... what is best..

I had given thought to somehow using something saved in USERS5 and then calling it up someway after LINE command to find block insertion point when touching either block or block attribute. But...

cheers

S

Link to comment
Share on other sites

Enjoy. :)

 

Remember, if you use Lee's, the point needs to be translated to UCS, as it will give undesired results if you are not WCS.

Link to comment
Share on other sites

Would a combination of techniques be more reliable when dealing with Inserts at odd orientations? See attached example.

 

Forgive me for the mixing and matching previously posted code. o:)

 

(defun c:AtInsert2 ( / obj )
 (if
   (setq obj
     (SelectifFoo
       (lambda ( x )
         (if
           (vlax-property-available-p
             (setq x (vlax-ename->vla-object x)) 'InsertionPoint
           )
           x
         )
       )
       "\nSelect Object: "
     )
   )
   (command "_.line" "_non"(trans (vlax-get obj 'InsertionPoint) 0 1))
 )
)
(defun SelectifFoo ( foo str / sel x )
 (while
   (progn
     (setq sel (entsel str))
     
     (cond
       (
         (vl-consp sel)

         (if (not (setq x (foo (car sel))))
           (princ "\n** Invalid Object Selected **")
         )
       )
     )
   )
 )
 x
)

Inserts.dwg

Link to comment
Share on other sites

Let's mix it up even more...

 

(defun c:AtInsert3 (/ obj)
 (if
   (setq obj
          (SelectifFoo
            (lambda (x)
              (if
                (vlax-property-available-p
                  (setq x (vlax-ename->vla-object x))
                  'InsertionPoint
                )
                 x
              )
            )
            "\nSelect Object: "
          )
   )
    ;; AJT begin edit
    ((lambda (ins)
       (if (eq 1 (logand 1 (getvar 'cmdactive)))
         ins
         (command "_.line" "_non" ins)
       )
     )
      (trans (vlax-get obj 'InsertionPoint) 0 1)
    )
    ;; AJT end edit
 )
)
(defun SelectifFoo (foo str / sel x)
 (while
   (progn
     (setq sel (entsel str))

     (cond
       (
        (vl-consp sel)

        (if (not (setq x (foo (car sel))))
          (princ "\n** Invalid Object Selected **")
        )
       )
     )
   )
 )
 x
)

Link to comment
Share on other sites

Let's mix it up even more...

 

(defun c:AtInsert3 (/ obj)
 (if
   (setq obj
          (SelectifFoo
            (lambda (x)
              (if
                (vlax-property-available-p
                  (setq x (vlax-ename->vla-object x))
                  'InsertionPoint
                )
                 x
              )
            )
            "\nSelect Object: "
          )
   )
    ;; AJT begin edit
    ((lambda (ins)
       (if (eq 1 (logand 1 (getvar 'cmdactive)))
         ins
         (command "_.line" "_non" ins)
       )
     )
      (trans (vlax-get obj 'InsertionPoint) 0 1)
    )
    ;; AJT end edit
 )
)
(defun SelectifFoo (foo str / sel x)
 (while
   (progn
     (setq sel (entsel str))

     (cond
       (
        (vl-consp sel)

        (if (not (setq x (foo (car sel))))
          (princ "\n** Invalid Object Selected **")
        )
       )
     )
   )
 )
 x
)

 

This is the best code yet !!! we are almost there !! when picking an attribute to begin the line, it does in fact start at the insertion point of the block, now if the second point or end of the line could likewise be picked from another attribute, (instead of entering 'AtInsert3), we would have the solution I was after ! thence continuing the line to the next attribute etc.....

Bravo Alan !!!

S

Link to comment
Share on other sites

(defun c:AtInsert3 (/ obj)
 (if
   (setq obj
          (SelectifFoo
            (lambda (x)
              (if
                (vlax-property-available-p
                  (setq x (vlax-ename->vla-object x))
                  'InsertionPoint
                )
                 x
              )
            )
            "\nSelect Object: "
          )
   )
    ;; AJT begin edit
    ((lambda (ins)
       (if (eq 1 (logand 1 (getvar 'cmdactive)))
         ins
         (command "_.line" "_non" ins "_non" (c:ATInsert3))
       )
     )
      (trans (vlax-get obj 'InsertionPoint) 0 1)
    )
    ;; AJT end edit
 )
)
(defun SelectifFoo (foo str / sel x)
 (while
   (progn
     (setq sel (entsel str))

     (cond
       (
        (vl-consp sel)

        (if (not (setq x (foo (car sel))))
          (princ "\n** Invalid Object Selected **")
        )
       )
     )
   )
 )
 x
)

 

Of course, if that's all you wanted, this could be a lot simpler.

Link to comment
Share on other sites

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...