Author Topic: Insert block from pull down menu  (Read 2137 times)

0 Members and 1 Guest are viewing this topic.

like_citrus

  • Newt
  • Posts: 114
Insert block from pull down menu
« on: March 14, 2020, 08:29:38 AM »
Hi, this is my first post.
The query relates to inserting a block from a pull down menu ... I have asked the query on two other forums over a few months span but still have not been able to resolve.

The initial part of the code allows me to insert a block with a unique name, by taking the filename of the block and appending the date to the nearest second. This part works fine now.

The next part of the code attempts to show the outline of the block and allow for snapping during insertion. Apparently this is not easy to achieve and a method has been developed by Lee Mac using GrSnap (http://www.lee-mac.com/grsnap.html).
Although it does work, what happens is that after insertion, a "zoom box" or "selection box" comes up automatically, which causes me to lose my workflow, ie, annoying.


NOTE:
- The custom menu is done with an MNU file, loaded using a SCR (script) file. There is one CAD file for each steel section. And all drawings, MNU file and SCR file are all placed in one folder.
- The LISP file is set to auto load.
- If testing, place attachments in C drive in a new folder called "Folder1".
- In the menu I have Universal Beams and Universal Columns. For testing purposes, the Universal Beams are inserted using the LSP code, and this is where I'm having problems.
- I know that this method may be old by now but I started it over 10 years ago and am now just returning to it. Please don't suggest other methods as it would be too difficult to start again, and stubbornly want to resolve this anyway.



roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Insert block from pull down menu
« Reply #1 on: March 14, 2020, 11:01:42 AM »
Maybe this helps:
Code: [Select]
(command "_.-insert" (strcat "MyNewName=" blkname) pause 1 "" 0)

like_citrus

  • Newt
  • Posts: 114
Re: Insert block from pull down menu
« Reply #2 on: March 14, 2020, 11:50:14 AM »
Many thanks for the response roy_043.
The modification is helpful and does what is required, including exit on Escape which I forgot to mention, so this is all positive.
The only issue is that the block is not renamed, the name stays as "MyNewName". Perhaps I have not inserted the line code in the correct location. Please see below.

Code: [Select]
(defun blkins (blkname / ent e_lst osf osm grr) ;the name of the program or function must be defined in the first statement
  ;command "-INSERT" blkname (list 0. 0. 0.) 1 "" 0) ;"1" is the scale, "0" is the rotation
  (command "_.-insert" (strcat "MyNewName=" blkname) pause 1 "" 0)
  (setq ent (entlast) e_lst (entget ent)
        osf (LM:grsnap:snapfunction)
        osm (getvar 'osmode)
    )
  (while (= (car (setq grr (grread T))) 5)  ; grread: used to have a dynamic display while dragging the cursor position.
    (princ "\rPick point: ")
    (redraw)
    (entmod (subst (cons 10 (trans (osf (cadr grr) osm) 1 0)) (assoc 10 e_lst) e_lst))
  )
  (if (or (= (car grr) 11) (= (car grr) 25)) (entdel ent) (command "-rename" "block" blkname  (strcat blkname "-" (rtos (getvar "cdate") 2 6))))
  (command "regenall")
  (princ)
)

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Insert block from pull down menu
« Reply #3 on: March 14, 2020, 01:31:48 PM »
Try using this:
Code: [Select]
(defun blkins (blkname)
  (command "_.-insert" (strcat blkname "-" (rtos (getvar "cdate") 2 6) "=" blkname) pause 1 "" 0)
)

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Insert block from pull down menu
« Reply #4 on: March 14, 2020, 02:15:09 PM »
Try using this:
Code: [Select]
(defun blkins (blkname)
  (command "_.-insert" (strcat blkname "-" (rtos (getvar "cdate") 2 6) "=" blkname) pause 1 "" 0)
)

If only someone haven't answerd this before...

https://forums.augi.com/showthread.php?174550-Insert-block-from-pull-down-menu-amp-Show-outline-shape/page2&p=#13
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

like_citrus

  • Newt
  • Posts: 114
Re: Insert block from pull down menu
« Reply #5 on: March 14, 2020, 08:53:37 PM »
Many thanks roy_043 as this simple line of code seems to work. I appreciate your assistance since it has taken a while to resolve.

marko, I did try the code you suggested in the AUGI forum, but as noted there was no hover and the block just inserted itself at the origin as shown in the attached image. Certainly the theme was correct but unfortunately as a beginner my skills are not good enough to interrogate the code.

Appreciate the assistance from both.

« Last Edit: March 15, 2020, 07:12:16 AM by like_citrus »