Visual LISP, AutoLISP and General Customization

Reply
*Expert Elite*
hmsilva
Posts: 2,639
Registered: ‎12-17-2004
Message 21 of 54 (300 Views)

Re: sweep multple polylines at once. Code does not work *yet*

04-26-2013 09:45 AM in reply to: Kent1Cooper

Kent1Cooper wrote:

...

 

EDIT:  Also, it looks like the routine does the Sweeping and then moves the result to the desired elevation.  I think the sequence should be different, if I'm interpreting Messages 8 and 10 correctly -- the Line/Polyline should be moved to the desired elevation first, then Sweep should be applied.

 

...

Kent,
my apologies, but when I answered I did not see the EDIT.

The order of operations has no influence on the final result, with exception, of the OP want to preserve the original lines, if so, you are completely correct, and will be necessary first change the elevation of the lines and then do the sweep...


Thank you!
Henrique

Contributor
l.l.oldescholtenhuis
Posts: 16
Registered: ‎05-03-2011
Message 22 of 54 (274 Views)

Re: sweep multple polylines at once. Code does not work *yet*

05-03-2013 08:18 AM in reply to: hmsilva

Hi Henrique and Kent,

 

Sorry for not responding so long, but I had to finish some other projects. I just played aroud with the script. It seems to do exactly what I want. As I'm not so much into LISP, i still have some questions you might be able to anwer:

 

- the script does not seem to work well with 3-point arcs. Do you know whether this might be resolved by using the sweep function instead of extrude?

 

- currently, all plines get the same diameter of tube. In reality, of course, electricity and water infrastructure are quite different in diameter. Would it be possible to add this nuance in the script? It might be nice if the drafter can insert diameters for each distinctive layer (e.g. water = 2, electricity = 0.5 etc.)

 

One additional challenge is the following: usually layer-names are not so nice as WATER, ELECTRICITY, GAS etc. I often get drawings with names such as water_replace, wtr, electr_highvolt, el, gas8Bar etc.  would it be possible for the TUBE-script to present these layers-names and ask the drafter to identify this as Water, Electricity or Gas category? 

 

 

*Expert Elite*
hmsilva
Posts: 2,639
Registered: ‎12-17-2004
Message 23 of 54 (262 Views)

Re: sweep multple polylines at once. Code does not work *yet*

05-03-2013 09:06 AM in reply to: l.l.oldescholtenhuis

Léon,

 

"the script does not seem to work well with 3-point arcs. Do you know whether this might be resolved by using the sweep function instead of extrude?"

 

the code I post here, use the command "sweep"...

 

"It might be nice if the drafter can insert diameters for each distinctive layer (e.g. water = 2, electricity = 0.5 etc.)"

 

in the code I post, is prompted to insert the diameter...

 

If you want, only with the purpose of testing, changes to the correct layer names and the correct elevation the code I post, and try it.


Henrique

Contributor
l.l.oldescholtenhuis
Posts: 16
Registered: ‎05-03-2011
Message 24 of 54 (237 Views)

Re: sweep multple polylines at once. Code does not work *yet*

05-07-2013 08:20 AM in reply to: hmsilva

Hi Henrique,

 

It seems that the code asks for a diameter, but that sweeps all the plines with this diameter. Would it be possible to insert a diameter separately for each layer?

 

Best

*Expert Elite*
Kent1Cooper
Posts: 5,231
Registered: ‎09-13-2004
Message 25 of 54 (218 Views)

Re: sweep multple polylines at once. Code does not work *yet*

05-14-2013 11:01 AM in reply to: l.l.oldescholtenhuis

l.l.oldescholtenhuis wrote:

.... 

- the script does not seem to work well with 3-point arcs. Do you know whether this might be resolved by using the sweep function instead of extrude?

 

- currently, all plines get the same diameter of tube. In reality, of course, electricity and water infrastructure are quite different in diameter. Would it be possible to add this nuance in the script? It might be nice if the drafter can insert diameters for each distinctive layer (e.g. water = 2, electricity = 0.5 etc.)

.... 


My earlier one works with Arcs for me.  In what way does it "not ... work well" for you?  [I can't test whether it's a matter of the difference between Sweep and Extrude.]

 

Here's a version that has separate diameters [but expressed as radii for simplicity in application] built in for each Layer [lightly tested]:

 

(defun C:TUBE (/ cmde osm elevrad ss ent lay)
  (setq
    cmde (getvar 'cmdecho)
    osm (getvar 'osmode)
    clay (getvar 'clayer)
    elevrad '("ELECTRICITY" 1 0.375 "WATER" -3 0.75 "GAS" -2.5 0.5)
      ; Layer names followed by elevation and conduit/pipe radius [edit numbers as appropriate]
  ); setq
  (setvar 'cmdecho 0)
  (setvar 'osmode 0)
  (prompt "\nTo put paths at Layer-based elevations and make tubular extrusions along them,")
  (if
    (setq ss (ssget '((0 . "*POLYLINE,LINE,ARC,CIRCLE,ELLIPSE,SPLINE") (8 . "ELECTRICITY,WATER,GAS"))))
    (repeat (sslength ss); then
      (setq
        ent (ssname ss 0)
        lay (strcase (cdr (assoc 8 (entget ent))))
      ); setq
      (command
        "_.move" ent ""
        (list 0 0 (cadr (member (setvar 'clayer lay) elevrad)))
          ; gets elevation value as item following Layer name in elevrad list,
          ; setting that Layer current in the process
        "" ; 'point' given was displacement -- finish Move
        "_.ucs" "_ZA"
          (vlax-curve-getStartPoint ent)
          (mapcar '+
            (vlax-curve-getStartPoint ent)
            (vlax-curve-getFirstDeriv ent (vlax-curve-getStartParam ent))
          ); mapcar & UCS
        "_.circle" "0,0" (caddr (member lay elevrad)); radius = 2nd number after Layer name
        "_.ucs" "_previous"
        "_.extrude" (entlast) "" "_path" ent
      ); command
      (ssdel (ssname ss 0) ss)
    ); repeat
    (prompt "\nNo qualifying object(s) selected."); else
  ); if
  (setvar 'cmdecho cmde)
  (setvar 'osmode osm)
  (setvar 'clayer clay)
  (princ)
); defun

 

Also, look into the DELOBJ System Variable, and set it appropriately for whether or not you would like to retain the Circles that it Extrudes.

 

EDIT:  It could be made to ask the User for diameters/radii each time [as the previous one did in the same-diameter-for-all approach], if that's preferable to building them into the code as constants.  Likewise, it could ask each time for the elevations to move each Layer's objects to.

Kent Cooper
*Expert Elite*
Kent1Cooper
Posts: 5,231
Registered: ‎09-13-2004
Message 26 of 54 (216 Views)

Re: sweep multple polylines at once. Code does not work *yet*

05-14-2013 11:05 AM in reply to: l.l.oldescholtenhuis

l.l.oldescholtenhuis wrote:

....

One additional challenge is the following: usually layer-names are not so nice as WATER, ELECTRICITY, GAS etc. I often get drawings with names such as water_replace, wtr, electr_highvolt, el, gas8Bar etc.  would it be possible for the TUBE-script to present these layers-names and ask the drafter to identify this as Water, Electricity or Gas category? 


I imagine that could be done, but it sounds pretty wide open.  Would it be valid to assume that all Water-related Layer names would at least start with a W, all Electricity-related ones with an E, and all Gas-related ones with a G?  That would make it a lot easier, I think.

Kent Cooper
Contributor
l.l.oldescholtenhuis
Posts: 16
Registered: ‎05-03-2011
Message 27 of 54 (210 Views)

Re: sweep multple polylines at once. Code does not work *yet*

05-14-2013 11:07 PM in reply to: Kent1Cooper
I'm afraid that that even that is not the case. Oftentimes, the service providers have their own coding systems for these layers.
To circumvent this, I thought it would be nice to have a script that allows the user to select and allocate the various layers to categories Electricity, Water, Gas. Perhaps we can use dropdown-menus or checkboxes for this?

Subsequently, the script uses the settings for various categories to move and extrude the polylines on the various layer.

I don't know whether this is possible at all, but it seems to me the most convenient solution.
*Expert Elite*
Kent1Cooper
Posts: 5,231
Registered: ‎09-13-2004
Message 28 of 54 (197 Views)

Re: sweep multple polylines at once. Code does not work *yet*

05-15-2013 09:00 AM in reply to: l.l.oldescholtenhuis

l.l.oldescholtenhuis wrote:
.... I thought it would be nice to have a script that allows the user to select and allocate the various layers to categories Electricity, Water, Gas. ....

You could do something like this [untested]:

 

(setq Electricity "" Water "" Gas ""); start with empty strings

(while

  (setq layname (cdr (assoc 2 (tblnext "layer" (not layname))))); name of next Layer

  (if

    (not

      (wcmatch

        (strcase layname)

        "0,DEFPOINTS,LAYER,NAMES,YOU,KNOW,ARE,NOT,IN,THOSE,CATEGORIES"

      ); wcmatch

    ); not

    (progn; then

      (initget 1 "Electricity Water Gas None")

      (setq cat

        (getkword

          (strcat "\nCategorize Layer " layname " [Electricity/Water/Gas/None]: ")

        ); getkword

      ); setq

      (if (/= cat "None"); User put into one of the categories

        (set (read cat) (strcat (eval (read cat)) layname ","); add to category's list of Layer names

      ); if [User-categorized]

    ); progn

  ); if [a Layer to be categorized or not]

); while [step through Layers]

 

Then you can use the variables Electricity, Water and Gas, which should hold comma-delimited strings of Layer names, in (ssget) filters to find the relevant things on all the Layers in each category together.

 

It could be built to have "None" be a default for which the User could hit Enter in categorizing, if you prefer.

Kent Cooper
*Expert Elite*
Kent1Cooper
Posts: 5,231
Registered: ‎09-13-2004
Message 29 of 54 (191 Views)

Re: sweep multple polylines at once. Code does not work *yet*

05-16-2013 07:25 AM in reply to: Kent1Cooper

Kent1Cooper wrote:
....
     (set (read cat) (strcat (eval (read cat)) layname ","); add to category's list of Layer names

....


That line should have another right parenthesis at the end:

 

        (set (read cat) (strcat (eval (read cat)) layname ",")); add to category's list of Layer names

Kent Cooper
Contributor
l.l.oldescholtenhuis
Posts: 16
Registered: ‎05-03-2011
Message 30 of 54 (176 Views)

Re: sweep multple polylines at once. Code does not work *yet*

05-17-2013 05:48 AM in reply to: hmsilva

I tried to integrate this with your previous script for extrusion. I think I did this wrong, as I cannot select any polyline for extrusion. Do you see where I need to adapt the complete script?

 

(defun C:TUBE (/ cmde osm elevrad ss ent lay)
(setq Electricity "" Water "" Gas ""); start with empty strings
(while
(setq layname (cdr (assoc 2 (tblnext "layer" (not layname))))); name of next Layer
(if
(not
(wcmatch
(strcase layname)
"0,DEFPOINTS,LAYER,NAMES,YOU,KNOW,ARE,NOT,IN,THOSE,CATEGORIES"
); wcmatch
); not
(progn; then
(initget 1 "Electricity Water Gas None")
(setq cat
(getkword
(strcat "\nCategorize Layer " layname " [Electricity/Water/Gas/None]: ")
); getkword
); setq
(if (/= cat "None"); User put into one of the categories
(set (read cat) (strcat (eval (read cat)) layname ",")); add to category's list of Layer names
); if [User-categorized]
); progn
); if [a Layer to be categorized or not]
); while [step through Layers]
elevrad '("ELECTRICITY" 1 0.375 "WATER" -3 0.75 "GAS" -2.5 0.5)
; Layer names followed by elevation and conduit/pipe radius [edit numbers as appropriate]
); setq
(setvar 'cmdecho 0)
(setvar 'osmode 0)
(prompt "\nTo put paths at Layer-based elevations and make tubular extrusions along them,")
(if
(setq ss (ssget '((0 . "*POLYLINE,LINE,ARC,CIRCLE,ELLIPSE,SPLINE") (8 . "ELECTRICITY,WATER,GAS"))))
(repeat (sslength ss); then
(setq
ent (ssname ss 0)
lay (strcase (cdr (assoc 8 (entget ent))))
); setq
(command
"_.move" ent ""
(list 0 0 (cadr (member (setvar 'clayer lay) elevrad)))
; gets elevation value as item following Layer name in elevrad list,
; setting that Layer current in the process
"" ; 'point' given was displacement -- finish Move
"_.ucs" "_ZA"
(vlax-curve-getStartPoint ent)
(mapcar '+
(vlax-curve-getStartPoint ent)
(vlax-curve-getFirstDeriv ent (vlax-curve-getStartParam ent))
); mapcar & UCS
"_.circle" "0,0" (caddr (member lay elevrad)); radius = 2nd number after Layer name
"_.ucs" "_previous"
"_.extrude" (entlast) "" "_path" ent
); command
(ssdel (ssname ss 0) ss)
); repeat
(prompt "\nNo qualifying object(s) selected."); else
); if
(setvar 'cmdecho cmde)
(setvar 'osmode osm)
(setvar 'clayer clay)
(princ)
); defun

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community