AutoLISP to offset closed polyline, hatch, and delete the second polyline [C3D]

AutoLISP to offset closed polyline, hatch, and delete the second polyline [C3D]

Anonymous
Not applicable
13,585 Views
106 Replies
Message 1 of 107

AutoLISP to offset closed polyline, hatch, and delete the second polyline [C3D]

Anonymous
Not applicable

Hi. In our firm, we often created partial hatches within buildings (represented by closed polylines). The process is as follows:
1. We select a closed polyline that was previously drawn and that represents the outline of a building.

2. We offset the polyline 2 units inside, creating a scaled version of the original polyline within the first. 

3. We hatch the area within the two polylines with a specific hatch pattern, scale, layer and color.

4. We delete the smaller, inside polyline, leaving the original building outline and the new hatch within.

I'm looking to automate this process in some way. I had some marginal success with the Action Recorder, but it wasn't consistent if the building outline was angled, and I had to always use the rightmost edge of the building. I'm sure AutoLISP can automate this sequence, but I'm a complete beginner.

Can anybody spoonfeed me a script that does what I'm looking for? Thanks a whole ton.

13,586 Views
106 Replies
Replies (106)
Message 41 of 107

Sea-Haven
Mentor
Mentor

Hi Kent the line type can use text styles or shx files. Like the idea of using | so angle is correct.

 

A,0,["|",TXT,S=1.41421356,X=-.5,Y=-.5,R=-45],-1.5

,TXT, is use a text style

,TXT.shx, is use a shape file 

 

*BATTING,Batting SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
A,.00254,-2.54,[BAT,ltypeshp.shx,x=-2.54,s=2.54],-5.08,[BAT,ltypeshp.shx,r=180,x=2.54,s=2.54],-2.54

 

PS Bricscad V20 does not have a txt.shx maybe Acad checks for both.

0 Likes
Message 42 of 107

Sea-Haven
Mentor
Mentor

Sorry double post

0 Likes
Message 43 of 107

john.uhden
Mentor
Mentor

@Kent1Cooper 

That is clever, but "this kind of thing" is really not what we're trying to accomplish.

But I did find out recently that drawing belgian block curb (showing joints) is easily accomplished by having a middle polyline with a thin (or even halftoned) dotted linetype and a width = the curb width and an ltscale that looks appropriate.

John F. Uhden

0 Likes
Message 44 of 107

JLJZPWBF
Enthusiast
Enthusiast

This is really awesome!! But I have a question or request. Instead of your lisp repeating how can I make it stop after selecting the side to offset to.  I need to have it ask me the offset distance every time. If it can stop I can make a repeating macro (with your lisp within it) where I can set my hatch layer, make it annotative, and set the hatch scale to 1.  We use different offsets depending on the size of our buildings. What you've made here is amazing!!!. I don't have to manually change the hatch rotation for every building. I'd really appreciate your help with this. I'm grateful for what you've done her.

The macro I made works 'just okay', but is very clunky, limited, hard to explain how to use and then I still have to change the hatch angle manually. It looks like this: 

 

*^C^C_INSERT;"G:/_CAD_Support/ToolPalette/LAYINS-SP.dwg";0,0;;;ERASE;L;;CHPROP;\\;LA;C_BLDG;;-LAYER;S;C_BLDG_NP;;O;L;C;\\\;-LAYER;S;C_BLDG_HATCH;;-HATCH;AD;A;N;;AN;Y;P;ANSI31;1;0;\;LAYERP;;

 

This part alone (O;L;C;\\\;) is the most difficult part  and I can't change the hatch rotation to 45 degrees of the building.  So if you can just make it stop or end after selecting the side to offset and let it do it's magic hatch, then I can make it repeat with all of the properites built within (and get rid of some of the stuff written in there) the macro that I have built.

 

 

0 Likes
Message 45 of 107

john.uhden
Mentor
Mentor

@JLJZPWBF 

Just hit Esc.  The *error* function is local.

As to the angle, I thought I had posted a revised version that gets its 45° from the polyline segment that you pick.

A "vertical" segment gets tilted one way and a "horizontal" segment the other way.

John F. Uhden

0 Likes
Message 46 of 107

JLJZPWBF
Enthusiast
Enthusiast

Everything about your routine works perfectly including the hatch rotation. I didn't get an error nor did I have to hit esc, all I had to do was add a semicolon for enter and it stopped it and went on to change the rest of the hatch properties. So it ended up looking like this: 

^C^C_INSERT;"G:/_Support/ToolPalette/LAYINS-SP.dwg";0,0;;;ERASE;L;;HATCHBLDG;\\\;-HATCHEDIT;L;P;ANSI31;1;;;L;LA;C_BLDG_HATCH;;L;AN;Y;

 

The problem is that as soon as I put an asterik in front to make my macro repeat, it freaks out and just keeps going in a loop, because your tool is designed to loop. So basically I can't make the macro repeat. I have to hit the button every time for every building.

 

Don't get me wrong, it's still much better than the one I had made, but when I have 100+ buildings it just gets tedious.  I was just hoping that it could stop after the 1st time, and have my macro do the repeat instead of the lisp. I don't know lisp well enough to know how to make it stop after it makes the 1st hatch. But I do like the open ended part of it so that I can change the properties within my tool.

 

I really appreciate your routine, I've been searching for something like this for a long time.

 

0 Likes
Message 47 of 107

john.uhden
Mentor
Mentor

@JLJZPWBF 

Hopefully this version does what you want.

John F. Uhden

0 Likes
Message 48 of 107

JLJZPWBF
Enthusiast
Enthusiast

It asks me for the distance, and I put it in, but then it just stops. It doesn't ask me for the object to select or what side to put the hatch on. I don't want to take advantage, just know that I really appreciate all of your help.

0 Likes
Message 49 of 107

john.uhden
Mentor
Mentor

@JLJZPWBF 

I had made a very hasty fix and left one line incorrect.

This one corrects that.

John F. Uhden

0 Likes
Message 50 of 107

JLJZPWBF
Enthusiast
Enthusiast

Well, it works like I asked, unfortunately I still can't use it as a repeat command, So here is my last ditch effort (as far as bugging you). I know that you aren't getting paid to do this, so I'm extremely grateful for all that you've put inot this.

 

The Original HatchBldg.lsp that I used works well, but since I can't make it a repeater in a macro, is there a way for it to ask me for the distance every time? It holds the value, so I can just enter thru it if it doesn't need to change. It would just be nice if I could enter a new value as needed, (without hitting escape and starting it over).  If not, it is what it is and it still much better than what I had before. So, again, thank you.

 

If you can make it do that, I'm going to ditch my property changes and just use your routine. I can make a separate macro that changes all of the properties for all of the building hatches at once, so that isn't a big deal. 

0 Likes
Message 51 of 107

JLJZPWBF
Enthusiast
Enthusiast

Regardless, it really is a great routine

 

0 Likes
Message 52 of 107

john.uhden
Mentor
Mentor

@JLJZPWBF 

I am thinking of mixing in my latest MakeCurrent.lsp so you can select an existing hatch followed by running HatchBldg.  But the latest are at work, not here at home.  Be patient.

And you wanted to be able to select a different offset for each entity selected?

John F. Uhden

0 Likes
Message 53 of 107

JLJZPWBF
Enthusiast
Enthusiast

Yes, I'd like it to be able to select a different offset for each entity selected, because even if it is the same offset distance I can just hit enter thru it because it holds the previous value when asked the offset distance. 

 

That sounds awesome, but I don't know what your other lisp does. Keeping it exactly the way you have it and just asking for a distance everytime would be perfect.

 

My macro makes the hatch pattern scale at 1, makes it annotative, and changes its layer without changing the current layer. Because they are used in large maps in Map 3D/Civil 3D maps they must be annotative. You don't have to include all that, I want to make it as easy as possible for you..

 

 

0 Likes
Message 54 of 107

john.uhden
Mentor
Mentor

@JLJZPWBF 

Okay.  Use your macro.

Attached is a new HatchBldg_1.4.lsp

;; v1.4 (9-06-22) moved offsetdist to within while loop; eliminated hpscale

 

John F. Uhden

0 Likes
Message 55 of 107

JLJZPWBF
Enthusiast
Enthusiast

Hi John,

I wasn't able to test this until just now. I'm not sure what happened, but as soon as I start it it gives me this error. (See screenshot)

0 Likes
Message 56 of 107

JLJZPWBF
Enthusiast
Enthusiast

I'm not sure if this will help, but when it loads it says:  error: extra right paren on input

0 Likes
Message 57 of 107

Sea-Haven
Mentor
Mentor

Worked for me, check what you copied then pasted to say Notepad.

0 Likes
Message 58 of 107

JLJZPWBF
Enthusiast
Enthusiast

Never mind, I loaded the wrong .lsp - It's perfect! Thank you. I appreciate that you changed the scale to 1 so that my macro changes them to annotative no matter what anno scale I'm at, THANK YOU!!!!

+

0 Likes
Message 59 of 107

john.uhden
Mentor
Mentor

@JLJZPWBF 

You are quite welcome.

I didn't change the scale to 1.  I just left it alone so that it would be up to you.

John F. Uhden

0 Likes
Message 60 of 107

MauCabrera789
Enthusiast
Enthusiast

@Kent1Cooper 

 

There's some fantastic contributions in this thread - I ended up sticking to your routine nonetheless for my hatching.

 

I've been wondering if it's possible to weave together this offset hatching program with another one of your programs I found in a separate thread for batch offset: OffsetInOrOut.lsp (found here).

 

This hatching program only allows for selection of one object at a time, but I'd think it could be a lot more useful if the program allowed you to select many objects at once to produce a lot of hatches at once. Based on the batch offset program I linked above, it already is possible to offset many objects at once - so maybe there's a way to use the batch offset program to create many hatches at one as well. What do you think?

 

 

0 Likes