Offset Both Sides and close

Offset Both Sides and close

Anonymous
Not applicable
13,622 Views
62 Replies
Message 1 of 63

Offset Both Sides and close

Anonymous
Not applicable

Is there a way to offset bothe sides of a line or polyline and close the offset line.  For example I would like to create a regtangle from offseting a line 3m.

0 Likes
Accepted solutions (4)
13,623 Views
62 Replies
Replies (62)
Message 21 of 63

kibitotato
Advocate
Advocate

Nice work. But it only works for closed plines... I´m looking for something that works with an open pline and if its possible I would like that the lisp ask for de width of the offset.

0 Likes
Message 22 of 63

Kent1Cooper
Consultant
Consultant

@kibitotato wrote:

Nice work. But it only works for closed plines... I´m looking for something that works with an open pline and if its possible I would like that the lisp ask for de width of the offset.


[You must have used the "Reply to the topic..." slot at the bottom, which always shows as being in Reply to the original poster of Message 1.  Instead, use the "REPLY" button at lower right in the specific Message you're Replying to.]

 

If that was in Reply to me at Message 20, yes, I specified that it's for closed ones.  Answer my questions there, and something can surely be done.  The code at Message 15 here includes asking for the distance, so it would be a matter of combining that with Offsetting to only one [which?] side, plus the Hatching part from the other link.

Kent Cooper, AIA
0 Likes
Message 23 of 63

kibitotato
Advocate
Advocate
Sorry. It´s my fault.
And yes. combining that with Offsetting to only one [which? - sometimes left and sometimes right. It depends....-] side, plus the Hatching part from the other link.
0 Likes
Message 24 of 63

kibitotato
Advocate
Advocate
So, is it possible to create the Offset to only one side selecting this one by clicking into the left or the right and plus the Hatching part... ¿? Thanks!!
0 Likes
Message 25 of 63

Sea-Haven
Mentor
Mentor

Try this the pick near end controls direction,

 

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/offset-both-sides-and-close/td-p/9425701/page/2
; By AlanH June 2023

(defun C:off1 ( / ent dist1 obj1 x obj2 pt2 pt1 pt3 oldsnap)
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 512)

(setq ent (entsel "Pick object to offset near start end "))

(setq obj1 (vlax-ename->vla-object (car  ent)))
(setq pt3 (cadr ent))
(setq start (vlax-curve-getstartPoint obj1))
(setq end (vlax-curve-getEndPoint obj1))

(setq d1 (distance pt3 end))
(setq d2 (distance pt3 start))
(if (< d1 d2)
  (progn
    (setq temp end)
    (setq end start)
    (setq start temp)
  )
)

(setq off (getreal "\nEnter offset -ve for left "))

(vla-offset obj1 off)

(setq obj2 (vlax-ename->vla-object (entlast)))
(setq start2 (vlax-curve-getstartPoint obj2))
(setq end2 (vlax-curve-getEndPoint obj2))
(command "line" Start start2 "")
(command "line" end end2 "")

(setq mp (mapcar '* (mapcar '+ start start2) '(0.5 0.5)))
(if (< off 0.0)
  (setq ang (angle start2 start))
  (setq ang (angle start start2))
)

(setq pt3 (polar mp (+ (/ pi 2) ang) 1))
(setq sc 1.0)
(setvar 'osmode 0)

(command "hatch" "P" "Ansi31" sc 0.0 pt3 "")

(setvar 'osmode oldsnap)
(princ)
)

 

a -ve offset is supported for go left not right.

 

 

0 Likes
Message 26 of 63

kibitotato
Advocate
Advocate
Sea-Haven thanks for your attention... but something is wrong I think... It doesn´t work for me. It works just like almost a normal offset...
0 Likes
Message 27 of 63

kibitotato
Advocate
Advocate
I found that I have to use _hatch instead of hatch because Ihave spanish autocad.
But It still doesn,t work properly.
1. It doesn´t work with an open pline
2 the hatch doens´t work properly because It asks about a perimeter, not picks the existent pline
0 Likes
Message 28 of 63

Kent1Cooper
Consultant
Consultant

@kibitotato wrote:
So, is it possible to create the Offset to only one side selecting this one by clicking into the left or the right and plus the Hatching part... ¿? Thanks!!

I'm working on it, melding elements of two source routines, but tell me about the Hatching:  Is there a pattern and scale and maybe rotation you would always want to use, as the OP did in my earlier link?  Or how much about it would you want to be asked each time?

Kent Cooper, AIA
0 Likes
Message 29 of 63

Sea-Haven
Mentor
Mentor

Works for me

 

SeaHaven_0-1686013232249.png

SeaHaven_1-1686013250893.png

 

 

0 Likes
Message 30 of 63

kibitotato
Advocate
Advocate
Comando: hatch Comando "HATCH" desconocido. Pulse F1 para obtener ayuda.
Comando: P Comando "P" desconocido. Pulse F1 para obtener ayuda.
Comando: Ansi31 Comando "ANSI31" desconocido. Pulse F1 para obtener ayuda.
...¿?
0 Likes
Message 31 of 63

Kent1Cooper
Consultant
Consultant

@kibitotato wrote:
Comando: hatch Comando "HATCH" desconocido. ....

Put the underscore prefix on things, to let the English command and option names work in other-language versions of AutoCAD:

(command "_.hatch" "_P" ....

or simply

(command "_hatch" "_P" ....

The period  .  prefix forces the use of the native command, in case there has been any redefinition.

Kent Cooper, AIA
0 Likes
Message 32 of 63

kibitotato
Advocate
Advocate

parcially fixed

But some things happen.

 

1 when the line is a 2 vertex line there is a malfunction and te minilines to close it doesn´t appear

 

2 I would like to have a joined pline when the offset is done

 

3 the hatch doen´t work always and when works maybe the perimeter is just a open pline

 

4 sometime the hatch ask to draw manually the perimeter

 

Thanks for your help

0 Likes
Message 33 of 63

Kent1Cooper
Consultant
Consultant

I see you did not add the underscore prefix to the "P" in the Hatch command.  Is "P" the right abbreviation in your language version of AutoCAD for what the command will ask?  BUT I find that when invoked in a (command) function [in Acad2020 that I have here] it goes right to asking for the pattern name, without the Properties option that you need when done manually.  Try omitting the "P" altogether.

 

I have mostly developed my combination of other routines to do what you're looking for.  Answer the question in Message 28, and I will be able to finish it.  Are the values in your latest OFF1.lsp what I should use?

Kent Cooper, AIA
0 Likes
Message 34 of 63

kibitotato
Advocate
Advocate
normally I use ANSI31, ANGLE 0, SCALE 0.005
0 Likes
Message 35 of 63

kibitotato
Advocate
Advocate

what is supposed to do the "P"
¿Is it previous?
Or Is it parameters of hacht?
I deleted it and it works sometimes like this

kibitotato_0-1686060528564.png

and some times this happens

 

Comando: _.hatch
Indique nombre de patrón o [?/Sólido/definido por el Usuario/Degradado] <ANSI31>: Ansi31
Precise escala del patrón <1.0000>: 1
Precise ángulo del patrón <0>: 0 Designe objetos para definir contornos de sombreado o <sombreado directo>,
Designe objetos: 0 encontrados
Designe objetos:
¿Retener contorno de polilínea? [Sí/No] <N>:

 

0 Likes
Message 36 of 63

Kent1Cooper
Consultant
Consultant

@kibitotato wrote:
normally I use ANSI31, ANGLE 0, SCALE 0.005

Try the OCH command in the attached OffsetCloseHatch.lspRead the comments at the top of the file.

 

I did not test all imaginable circumstances -- if something doesn't work, let me know.

 

It changes the UCS to match each object, so that it can work on things in different Coordinate Systems, but that also has what I consider a positive effect:  with a Line that's close to the basic angle of the lines in the ANSI31 pattern [at 45° when used at rotation of 0°], it produces the left situation in this image, rather than the right:

Kent1Cooper_0-1686067462317.png

But surely sometimes it will give you a result at a rotation you don't like -- you can easily change it in Properties or the Hatch Editor in the ribbon.

 

[I confess to being curious about what you are drawing -- that's a really tiny Hatch scale!]

Kent Cooper, AIA
Message 37 of 63

Kent1Cooper
Consultant
Consultant

@kibitotato wrote:

what is supposed to do the "P" ....


[That should have been directed to @Sea-Haven who wrote the code with the "P" in it, not to me, but anyway....]

 

Try it in Command:-line operation [-HATCH] manually, and see the prompt line.  The first option [in the English version] is Properties, which you need to call for in order to get to where it asks for a pattern name.  But when used inside an AutoLisp (command) function, it doesn't use the same prompt sequence as it does at the regular Command: line, and that option is not appropriate for what it is asking at the time.

Kent Cooper, AIA
Message 38 of 63

kibitotato
Advocate
Advocate
It works!!!! Thank you so much!!!! Awesome!!!!
But... Just two things. In order to be perfect.
1 Is it possible that the hatch was associative with the closed line? In my office we use all the hatches associative in order to work easily with the later changes to the model
2 And would the hatch can be at the layer hatch, not the current layer..... ¿?

I draw buildings.. I´m an architect. We use this hatch for some walls. Almost like a solid hacth but more vibrating

0 Likes
Message 39 of 63

Kent1Cooper
Consultant
Consultant

Investigate the HPASSOC and HPLAYER System Variables.  [It's possible those may not be honored when the Hatch is done from within an AutoLisp (command) function -- I can't try right now.]

Kent Cooper, AIA
0 Likes
Message 40 of 63

kibitotato
Advocate
Advocate
Ok im not in a hurry.
systema variables are ok but doesn´t works...

thanks
0 Likes