Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Change Polyline with Global Width to hatch

14 REPLIES 14
Reply
Message 1 of 15
Stuboy
9530 Views, 14 Replies

Change Polyline with Global Width to hatch

I have a bolt program that draws the thickness of a bolts in elevation as a polyline with a global width, what i need is a lisp to then change this lwpolyline to a hatch, ie if global width is 20 and the polyline is 30 long i need to change this to a 20x30 solid hatch, is it possible to get the the global width and length and convert this to a boundary hatch? I need the same thing done for bolts in plan too as the circle is a lwpolyline also.

SB
14 REPLIES 14
Message 2 of 15
scottbolton
in reply to: Stuboy

Stu,

This does what you're after for the elevation. There's no error checking so ensure you only pick LWPOLYLINEs (or add a check). Also, if the global width is 0.0 then this is changed to 1.0 (*** here). The original and outline are deleted at the end, leaving only the hatch. You could get the layer and colour from the original end make the hatch the same - knock yursel out!

The circle in plan can be done in a similar way.

S

(defun c:SB4SB ( / CONT COUNT END1 END2 ENT ENT1 ENT2 ENTFINAL OBJ OBJ1 OBJ2 SS SSTEMP START1 START2 WIDTH)
(setq ss (ssget)
count 0
)
(repeat (sslength ss)
(setq ent (ssname ss count)
obj (vlax-ename->vla-object ent)
cont (entget ent)
width (cdr (assoc 43 cont))
cont (subst '(43 . 0.0) (assoc 43 cont) cont)
)
(entmod cont)
(if (= 0.0 width) (setq width 1.0)); < *** ;
(vla-Offset obj (/ width 2.0))
(setq ent1 (entlast))
(vla-Offset obj (/ width -2.0))
(setq ent2 (entlast)
obj1 (vlax-ename->vla-object ent1)
obj2 (vlax-ename->vla-object ent2)
start1 (vlax-curve-getStartPoint obj1)
start2 (vlax-curve-getStartPoint obj2)
end1 (vlax-curve-getEndPoint obj1)
end2 (vlax-curve-getEndPoint obj2)
sstemp (ssadd)
)
(ssadd ent2 sstemp)
(entmake (append
'((0 . "LWPOLYLINE") (100 . "AcDbEntity") (8 . "0") (100 . "AcDbPolyline") (90 . 2))
'((70 . 0) (43 . 0.0) (38 . 0.0) (39 . 0.0))
(list (cons 10 start1))
'((40 . 5.0) (41 . 5.0) (42 . 0.0))
(list (cons 10 start2))
'((40 . 5.0) (41 . 5.0) (42 . 0.0) (210 0.0 0.0 1.0))
)
)
(ssadd (entlast) sstemp)
(entmake (append
'((0 . "LWPOLYLINE") (100 . "AcDbEntity") (8 . "0") (100 . "AcDbPolyline") (90 . 2))
'((70 . 0) (43 . 0.0) (38 . 0.0) (39 . 0.0))
(list (cons 10 end1))
'((40 . 5.0) (41 . 5.0) (42 . 0.0))
(list (cons 10 end2))
'((40 . 5.0) (41 . 5.0) (42 . 0.0) (210 0.0 0.0 1.0))
)
)
(ssadd (entlast) sstemp)
(command "_join" ent1 sstemp "")
(setq entfinal (entlast))
(command "_hatch" "_P" "_SOLID" entfinal "")
(entdel ent)
(entdel entfinal)
(setq count (1+ count))
)
) Edited by: ScottBolton on Feb 9, 2010 4:46 AM
Message 3 of 15
Stuboy
in reply to: Stuboy

Thanks Scotty,

Absoulute lifesaver mate...

Here is one for the PLAN, no errors checks on it either....

(defun c:rbp (/)

(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(vla-EndUndoMark ActDoc)
(vla-StartUndoMark ActDoc)
(setq cnt -1)
(if (setq ss (ssget "x" (list '(0 . "LWPOLYLINE") (cons 410 (getvar
"ctab")))))
(while (setq Ent (ssname ss (setq cnt (1+ cnt))))
(if
(and
(equal (length (setq CoordList (vlax-get (setq Obj
(vlax-ename->vla-object Ent)) 'Coordinates))) 4)
(equal (vla-GetBulge Obj 0) (vla-GetBulge Obj 1))
)
(progn
(setq CtPt
(list
(/ (+ (car CoordList) (caddr CoordList)) 2.0)
(/ (+ (cadr CoordList) (cadddr CoordList)) 2.0)
(vla-get-Elevation Obj)
)
)
(setq Dia (distance (list (car CoordList) (cadr CoordList)) (list (caddr
CoordList) (cadddr CoordList))))
(setq Dia (+ Dia (vla-get-ConstantWidth Obj)))
(entmake
(list
(cons 0 "CIRCLE")
(cons 10 CtPt)
(cons 40 (/ Dia 2.0))
(cons 8 (vla-get-Layer Obj))
(cons 6 (vla-get-Linetype Obj))
(cons 48 (vla-get-LinetypeScale Obj))
)
)
(command "-hatch" "P" "SOLID" "S" "LAST" "" "")
(command "_.chprop" "LAST" "" "LA" "35CONT" "")
)
)
)
)
(vla-EndUndoMark ActDoc)
(princ)
)
Message 4 of 15
lisaallard2832
in reply to: Stuboy

Hi, I have tried the lisp for converting plines to hatches but I get an error:

; error: no function definition: VLAX-ENAME->VLA-OBJECT

 Any tips?

Message 5 of 15
hmsilva
in reply to: lisaallard2832

Try

(vl-load-com)

 

Henrique

EESignature

Message 6 of 15
lisaallard2832
in reply to: hmsilva

I am really unfamiliar with lisp routines, could you be more specific about how I should go about?

 

Thanks!

Message 7 of 15
hmsilva
in reply to: lisaallard2832

Hy

 

(vl-load-com);;Loads Visual LISP extensions to AutoLISP

just copy and paste in the code just after

 

(defun c.......)

(vl-load-com)<--

rest of the code....

 

Cheers

Henrique

EESignature

Message 8 of 15
lisaallard2832
in reply to: hmsilva

Worked like a charm! Thank you so much!!

 

Lisa

Message 9 of 15
Kent1Cooper
in reply to: Stuboy


@Stuboy wrote:
I have a bolt program that draws the thickness of a bolts in elevation as a polyline with a global width, what i need is a lisp to then change this lwpolyline to a hatch, ie if global width is 20 and the polyline is 30 long i need to change this to a 20x30 solid hatch, is it possible to get the the global width and length and convert this to a boundary hatch? I need the same thing done for bolts in plan too as the circle is a lwpolyline also.

SB


Here's something I developed not long ago, that will do that: PLWtoOutline&Hatch.lsp with its PLWOH command.  It will do it with any Polyline of global width, of any number of segments, open or closed, and to as many of them as you want to select at one time.  I tailored it as posted here to use the SOLID pattern, non-associative, but it has instructions to adjust it for other patterns and/or for associativity.  As it is currently, it keeps the boundary Polyline(s) that it builds along the edges of the global-width one(s) selected, but could easily be adjusted to delete them instead.  See additional comments at the top of the file.

Kent Cooper, AIA
Message 10 of 15
hmsilva
in reply to: lisaallard2832

You're welcome, Lisa.

Glad i could help.

 

Henrique

EESignature

Message 11 of 15
superkb
in reply to: Kent1Cooper

hi!

 

I have big problem,

I running Your script "PLWtoOutline&Hatch.lsp" and working well, but with continuous line, but with diferent line it still change any type of line to continuous line. as effect, I want to change Polylines with Global Width to Boundaries of it  but all types of line. for example ACAD_ISO03W100

 

can You help me?

sorry for bad english

 

best regards

Message 12 of 15
Kent1Cooper
in reply to: superkb



@superkb wrote:

....

I running Your script "PLWtoOutline&Hatch.lsp" and working well, but with continuous line, but with diferent line it still change any type of line to continuous line. as effect, I want to change Polylines with Global Width to Boundaries of it  but all types of line. for example ACAD_ISO03W100

....


Welcome to the Forums!

 

Since the routine [which is not a Script -- that has a specific meaning in AutoCAD, and this doesn't fit the definition] converts a Polyline with width into a perimeter and Hatches that, given that it uses the Solid pattern, it will necessarily result in a continuous filled area.  It sounds to me as though you want to turn a non-continuous-linetype Polyline with width into something that looks the same, but is a Hatch pattern [I assume still in the Solid pattern] in multiple areas, or maybe separate Hatch patterns for each dash in the non-continuous linetype.  If that's correct, it may be possible, though I don't think it will be easy.  [But if that's correct, it does make me wonder why you need it to be someththe non-continuous Polyline.]
 

A sample illustration or drawing file would be helpful, to understand what you're looking for.

Kent Cooper, AIA
Message 13 of 15
oriole.phillips
in reply to: superkb

Where do you get this Lisp file? PLWtoOutline&Hatch.lsp

 

Message 14 of 15


@oriolep wrote:

Where do you get this Lisp file? PLWtoOutline&Hatch.lsp

 


It's an attachment at Post 9 on this thread.

Kent Cooper, AIA
Message 15 of 15
saifumk8
in reply to: scottbolton

Thank you Scottbolton,

It's really helpful.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost