Jump to content

Blocks trimming lines on insertion


Recommended Posts

Is there a way to create a block that could trim a line when you insert it? The block I'm using is not rectangular, so to create a wipeout for this block would only mess it up. I know could just click the 2 ends of the lines and trim what's in between, but I have many of these blocks to insert, and having to avoid this step would save a lot of time. :sweat:

 

I don't know if this feature is on the new version of AutoCAD, but I'm running AutoCAD 2008. Any suggestions?

Union.jpg

Link to comment
Share on other sites

This should work for most blocks:

 

[i][color=#990099];; Auto Block Break by Lee McDonnell  ~  27.11.2009[/color][/i]

[i][color=#990099];; Will Break Object by Rectangular Block Width at 0 Rotation.[/color][/i]

[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:ins [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] *error* doc spc vl ov bNme pt uFlag
                       Obj ent Minp Maxp lst dis ang[b][color=RED])[/color][/b]
 [b][color=Red]([/color][color=Blue]vl-load-com[/color][color=Red])[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] *error* [b][color=RED]([/color][/b]msg[b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] uFlag [b][color=RED]([/color][/b][b][color=BLUE]vla-EndUndoMark[/color][/b] doc[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] ov [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]setvar[/color][/b] vl ov[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]or[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]wcmatch[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcase[/color][/b] msg[b][color=RED])[/color][/b] [b][color=#ff00ff]"*BREAK,*CANCEL*,*EXIT*"[/color][/b][b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=#ff00ff]"\n** Error: "[/color][/b] msg [b][color=#ff00ff]" **"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] doc [b][color=RED]([/color][/b][b][color=BLUE]vla-get-ActiveDocument[/color][/b]
             [b][color=RED]([/color][/b][b][color=BLUE]vlax-get-Acad-Object[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
       
       spc [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]zerop[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-activespace[/color][/b] doc[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
             [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]=[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-mspace[/color][/b] doc[b][color=RED])[/color][/b] [b][color=Blue]:vlax-true[/color][color=RED])[/color][/b]
               [b][color=RED]([/color][/b][b][color=BLUE]vla-get-modelspace[/color][/b] doc[b][color=RED])[/color][/b]
               [b][color=RED]([/color][/b][b][color=BLUE]vla-get-paperspace[/color][/b] doc[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
             [b][color=RED]([/color][/b][b][color=BLUE]vla-get-modelspace[/color][/b] doc[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] vl [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=#ff00ff]"CMDECHO"[/color][/b] [b][color=#ff00ff]"OSMODE"[/color][/b][b][color=RED])[/color][/b] ov [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]getvar[/color][/b] vl[b][color=RED])[/color][/b][b][color=RED])[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]progn[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] bNme [b][color=RED]([/color][/b][b][color=BLUE]getstring[/color][/b] [b][color=BLUE]t[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=#ff00ff]"\nSpecify Block Name <"[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]getvar[/color][/b] [b][color=#ff00ff]"INSNAME"[/color][/b][b][color=RED])[/color][/b] [b][color=#ff00ff]"> : "[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

     [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b]  [b][color=RED]([/color][/b][b][color=BLUE]eq[/color][/b] [b][color=#ff00ff]""[/color][/b] bNme[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] bNme [b][color=RED]([/color][/b][b][color=BLUE]getvar[/color][/b] [b][color=#ff00ff]"INSNAME"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=BLUE]nil[/color][/b][b][color=RED])[/color][/b]

           [b][color=RED]([/color][/b]  [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]snvalid[/color][/b] bNme[b][color=RED])[/color][/b]
                   [b][color=RED]([/color][/b][b][color=BLUE]or[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]tblsearch[/color][/b] [b][color=#ff00ff]"BLOCK"[/color][/b] bNme[b][color=RED])[/color][/b]
                       [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] bNme [b][color=RED]([/color][/b][b][color=BLUE]findfile[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] bNme [b][color=#ff00ff]".dwg"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=BLUE]nil[/color][/b][b][color=RED])[/color][/b]

           [b][color=RED]([/color][/b][b][color=BLUE]t[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#ff00ff]"\n** Block not Found **"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
           
 [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] pt [b][color=RED]([/color][/b][b][color=BLUE]getpoint[/color][/b] [b][color=#ff00ff]"\nSelect Point for Block: "[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]progn[/color][/b]    
     [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] uFlag [b][color=RED]([/color][/b][b][color=BLUE]not[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-StartUndoMark[/color][/b] doc[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
             
           Obj   [b][color=RED]([/color][/b][b][color=BLUE]vla-InsertBlock[/color][/b] spc [b][color=RED]([/color][/b][b][color=BLUE]vlax-3D-point[/color][/b] pt[b][color=RED])[/color][/b] bNme [b][color=#009999]1.[/color][/b] [b][color=#009999]1.[/color][/b] [b][color=#009999]1.[/color][/b] [b][color=#009999]0.[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
      [b][color=RED]([/color][/b][b][color=BLUE]setvar[/color][/b] [b][color=#ff00ff]"INSNAME"[/color][/b] bNme[b][color=RED])[/color][/b]  

     [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ent [b][color=RED]([/color][/b][b][color=BLUE]car[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]nentselp[/color][/b] pt[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
              [b][color=RED]([/color][/b][b][color=BLUE]not[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-catch-all-error-p[/color][/b]
                     [b][color=RED]([/color][/b][b][color=BLUE]vl-catch-all-apply[/color][/b]
                       [b][color=DARKRED]'[/color][/b][b][color=BLUE]vlax-curve-getEndParam[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] ent[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]progn[/color][/b]
         [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] pt [b][color=RED]([/color][/b][b][color=BLUE]vlax-curve-getClosestPointto[/color][/b] ent pt[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
         
         [b][color=RED]([/color][/b][b][color=BLUE]vla-getBoundingBox[/color][/b] Obj [b][color=DARKRED]'[/color][/b]Minp [b][color=DARKRED]'[/color][/b]Maxp[b][color=RED])[/color][/b]
         [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] lst [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]vlax-safearray->list[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] Minp Maxp[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
               dis [b][color=RED]([/color][/b][b][color=BLUE]-[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]caadr[/color][/b] lst[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]caar[/color][/b] lst[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

         [b][color=RED]([/color][/b][b][color=BLUE]vla-put-Rotation[/color][/b] Obj
           [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ang [b][color=RED]([/color][/b][b][color=BLUE]angle[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=#009900]0[/color][/b] [b][color=#009900]0[/color][/b] [b][color=#009900]0[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-curve-getFirstDeriv[/color][/b] ent
                                       [b][color=RED]([/color][/b][b][color=BLUE]vlax-curve-getParamatPoint[/color][/b] ent pt[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
         [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]setvar[/color][/b] vl [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=#009900]0[/color][/b] [b][color=#009900]0[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
         [b][color=RED]([/color][/b][b][color=BLUE]command[/color][/b] [b][color=#ff00ff]"_.break"[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] ent pt[b][color=RED])[/color][/b]
                  [b][color=#ff00ff]"_F"[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]osnap[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]polar[/color][/b] pt ang [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] dis  [b][color=#009999]2.[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=#ff00ff]"_nea"[/color][/b][b][color=RED])[/color][/b]
                       [b][color=RED]([/color][/b][b][color=BLUE]osnap[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]polar[/color][/b] pt ang [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] dis [b][color=#009999]-2.[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=#ff00ff]"_nea"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
         [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]setvar[/color][/b] vl ov[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

     [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] uFlag [b][color=RED]([/color][/b][b][color=BLUE]vla-EndUndomark[/color][/b] doc[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
 
 [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

           

           

Link to comment
Share on other sites

Yes, its not a big one, it just means the Visual LISP console isn't loaded.

 

Most people (me included) have (vl-load-com) in their ACADDOC.lsp and so don't realise if (vl-load-com) is missing from code.

 

I have updated my code in my previous post, it should work now.

Link to comment
Share on other sites

I have updated my code in my previous post, it should work now.

 

Thanks Lee Mac. It works now.:)

 

I'm going to use this lisp for now to finish my job, but I was wondering for the future, could this lisp have the option of browsing for other blocks?

 

Also, I don't know if there is a fourm that explains how to do this, but is there any way to create a button that loads the lisp?:unsure:

 

Thanks again,

 

Ivan8)

Link to comment
Share on other sites

Thanks Lee Mac. It works now.:)

 

Excellent - good to hear.

 

I'm going to use this lisp for now to finish my job, but I was wondering for the future, could this lisp have the option of browsing for other blocks?

 

The LISP should work for most blocks - (assuming they don't have any protruding features).

 

Also, I don't know if there is a fourm that explains how to do this, but is there any way to create a button that loads the lisp?:unsure:

 

To automatically load the LISP on startup, you can either add it to the Startup Suite on the appload dialog.

 

Or, alternatively, you can create an ACADDOC.lsp in your ACAD search path and put a call, like this in it:

 

(load "ins.lsp" "Load Failed")

 

More info here:

 

Auto-Loading LISP (ACADDOC.lsp etc):

 

http://www.theswamp.org/index.php?topic=30946.msg364983#msg364983

 

http://www.cadtutor.net/faq/questions/53/How+do+I+automatically+load+variables%3F

 

To call the LISP from a button, create a new button, and in the Macro Box put this:

 

^C^C(c:ins)

Link to comment
Share on other sites

  • 5 months later...

Lee Mac,

I tried your code and it does work but it doesn't trim the lines to the edge of the block. Some blocks work correctly some don't. I would like to use this to create a custom toolbar to place P&ID symbols. Is it possible to alter the code to work something like this for a button macro...

Button macro

-start ins command

-specify block name for button

-total length of line break

^C^Cc:ins;block_name.dwg;###;

Also could you add a way to search a specific directory if the block isn't in the current drawing?

I'm trying to figure this stuff out on my own but my knowledge of code is limited. Any help would be greatly appreciated.

Thanks

Link to comment
Share on other sites

Hi,

 

The code assumes a central base point and calculates the trim points using the rectangular size of the block, so it may not be suitable for all blocks...

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