Need to change line colour after double offset

chris22d
Explorer
Explorer

Need to change line colour after double offset

chris22d
Explorer
Explorer

Hi all,

 

I've been working on a LISP for a week or so and I'm nearly there but can;t seem to finish it.

I'm trying to make a script for drawing duct work. Basically it goes Select Line>Specify duct diameter>change colour to 1 (red) and line type>fillet by diameter>double offset>change new offset lines to colour 2 (yellow) and line type to continuous.
I've done all but the final step and can't work out what I'm missing. 

 

Here's my script so far:

(defun C:ee(/ ent ep num1 num2 obj obj1 obj2 of pte pts sp)
(or (vl-load-com))
(if (setq ent (entsel))
(progn
(setq of1 (getdist "\n Specify duct diameter: ")
of (/ of1 2))

(command "fillet" "r" of1 "fillet" "p" ent "" )
(command "chprop" ent "" "c" "1" "lt" "CENTER2" "")

(setq obj (vlax-ename->vla-object (car ent)))
(setq num1 0
num2 (1- (/ (length (vlax-get obj 'Coordinates)) 2))
)
(setq sp (vlax-curve-getstartpoint obj)
ep (vlax-curve-getendpoint obj)
)
(setq obj1 (vlax-invoke obj 'Offset of))
(setq obj2 (vlax-invoke obj 'Offset (* -1 of)))

(setq pts
(vlax-safearray-fill
(vlax-make-safearray vlax-vbdouble '(1 . 1))
(list (car sp)(cadr sp)))
pte
(vlax-safearray-fill
(vlax-make-safearray vlax-vbdouble '(1 . 1))
(list (car ep)(cadr ep))))
(vla-put-coordinate (car obj1) num1 pts)
(vla-put-coordinate (car obj2) num1 pts)
(vla-put-coordinate (car obj1) num2 pte)
(vla-put-coordinate (car obj2) num2 pte)

)
)

(princ)
)

 

 

Any thoughts?



0 Likes
Reply
Accepted solutions (1)
1,369 Views
3 Replies
Replies (3)

Kent1Cooper
Consultant
Consultant
Accepted solution

@chris22d wrote:

... Select Line>Specify duct diameter>change colour to 1 (red) and line type>fillet by diameter>double offset>change new offset lines to colour 2 (yellow) and line type to continuous.
….
(setq obj (vlax-ename->vla-object (car ent)))

….


It looks more complex than I think it needs to be.  I think, after the code line quoted above, you could just do:

 

(vla-offset obj of)

(command "chprop" (entlast) "" "c" "2" "lt" "Continuous" "")

(vla-offset obj (- of))

(command "chprop" (entlast) "" "c" "2" "lt" "Continuous" "")

Kent Cooper, AIA
0 Likes

chris22d
Explorer
Explorer

Spot on there, Sir! What a champ.

I really did make things complicated for myself didn't I?

 

My next question would be how would I go about creating the option to select multiple lines? 
I've changed from entsel to ssget, which allows me to select multiple lines, but am I now reaching the limits of my simple offset command? Would I then be needing something a bit more complex?

Thanks in advance!

 

0 Likes

Kent1Cooper
Consultant
Consultant

@chris22d wrote:

.... how would I go about creating the option to select multiple lines? 
I've changed from entsel to ssget, which allows me to select multiple lines, but am I now reaching the limits of my simple offset command? Would I then be needing something a bit more complex?....


Not very much more complex.  You just need to step through the selection and run the process on each thing in it.  Since you're Offsetting to both sides and can just use (vla-offset) with positive and negative values, you don't need to calculate locations for to-which-side points.  [And I assume by "lines" you really mean Polylines -- a Line is a distinctly different thing in AutoCAD.]

 

Something like this, if your (ssget) stores what it finds in a variable called 'ss':

 

(setvar 'filletrad of1); [to eliminate the Radius option in Fillet every time]

(repeat (setq n (sslength ss))

  (setq ent (ssname ss (setq n (1- n)))); [starts at the end and counts down]

  (command

    "fillet" "p" ent ""
    "chprop" ent "" "c" "1" "lt" "CENTER2" ""

  )
  (setq obj (vlax-ename->vla-object ent)); [ent is now the entity name directly]

  (vla-offset obj of)

  (command "chprop" (entlast) "" "c" "2" "lt" "Continuous" "")

  (vla-offset obj (- of))

  (command "chprop" (entlast) "" "c" "2" "lt" "Continuous" "")

); repeat

Kent Cooper, AIA
0 Likes