Jump to content
loudy000

run command for each polyline help

Recommended Posts

loudy000

hey guys, 

 

i have a little knowledge on c#, basically i want to do something like

 

foreach(Polyline pl in selected polylines)

{

///do something }; 

 

but i dont have any idea how to do it using lisp.

 

 

this is the command i want to run for each polyline

 (command "_MAPCreateFeatureFromGeometry" "yes" "landuse" "")

)

 

thanks in advance.

Share this post


Link to post
Share on other sites
Tharwat

Hi,

That is an iteration process and here is one way as in the following :

(if (setq ss (ssget "_:L" '((0 . "LWPOLYLINE"))))
  (repeat (setq no (sslength ss))
    (setq sn (ssname ss (setq no (1- no))))
    ;; do something here for the polyline entity. 'sn' = 'pl' as into your example
    )
  )

NOTE: How come that command call does not have the entity itself to run with ? the variable 'pl' as into your example !

Share this post


Link to post
Share on other sites
loudy000

Hi @Tharwat sorry, here's the full command i want to repeat for each selected polyline

 

(Defun c:pll ()
(while (setq s (ssget))
  (sssetfirst nil s)
  (command "_MAPCreateFeatureFromGeometry" "yes" "Landuse" """")
))
 

 

Thank you i dont know how to incorporate it in your code, i tried pasting it under don something but it's not working. Again Thank you.

Share this post


Link to post
Share on other sites
Tharwat

Does this command "_MAPCreateFeatureFromGeometry" require the polylines to be selected ( highlighted ) in prior ?

Share this post


Link to post
Share on other sites
loudy000

yes please, so the work flow is

 

1. Select Polylines

2. then run that command for each selected polyline

 

Thanks for your help

Share this post


Link to post
Share on other sites
Tharwat

But you did not include the variable 'pl' within the posted codes into your first post ?

(command "_MAPCreateFeatureFromGeometry" "yes" "landuse" "")

Share this post


Link to post
Share on other sites
loudy000

oh sorry you have to run that command first then apply to each polyline, currently working with single polyline

 

so command, then select polylines

Share this post


Link to post
Share on other sites
Tharwat

Something like this?

(defun c:Test ( / ss)
  (if (setq ss (ssget "_:L" '((0 . "*POLYLINE"))))
     (command "_MAPCreateFeatureFromGeometry" ss "" "yes" "landuse" "")
    )
  (princ)
  )

Share this post


Link to post
Share on other sites
loudy000

Thanks @Tharwat however i still cant get it to work, sorry it's kind of difficult to explain what  the command does..

Please see attached. so thats basically i want to run on multiple polylines as separate (fill)

 

Thanks again.

 

 

Untitled Project.gif

Share this post


Link to post
Share on other sites
Tharwat

Hopefully the following would work and you may need to use the system variable filedia to disable the prompt of the Dialog box.

(defun c:Test ( / ss no)
  (if (setq ss (ssget "_:L" '((0 . "*POLYLINE"))))
    (repeat (setq no (sslength ss))
     (command "_MAPCreateFeatureFromGeometry" "landuse" "" (ssname ss (setq no (1- no))) "" "yes")
      )
    )
  (princ)
  )

 

Share this post


Link to post
Share on other sites
loudy000

Thanks again, appreciate your help however it only works with single poly line. I modify it a bit because above code is not working. cheers

(defun c:Test ( / ss no)
  (if (setq ss (ssget "_:L" '((0 . "*POLYLINE"))))
    (repeat (setq no (sslength ss))
     (command "MAPCreateFeatureFromGeometry" "Landuse MP" (ssname ss (setq no (1- no))) "" "yes")
      )
    )
  (princ)
  )

 

Untitled Project.gif

Share this post


Link to post
Share on other sites
Tharwat

Can you post the working C# codes so I can convert them into lisp if they are not that complicated?

You did not show the command line if the codes throw any error to allow me to know how things going on with the codes.!

Share this post


Link to post
Share on other sites
BIGAL

Like Tharwat are you just hatching multiple plines, doing an inside parallel pline. or other options. What I am suggesting is the options may all be done already in lisp.

 

Ssget has multiple select filters that you can use and can be multiple of,  such as layer, all or all in a particular space model / layout.

 

 

  • Like 1

Share this post


Link to post
Share on other sites
loudy000
Posted (edited)
10 hours ago, Tharwat said:

Can you post the working C# codes so I can convert them into lisp if they are not that complicated?

You did not show the command line if the codes throw any error to allow me to know how things going on with the codes.!

Hi @Tharwat technically there's no actual c# code it's just an example of what im after, i think it's close just need to create separate hatch for each poly line. So say select 3 or 4..poly lines and create hatch for each.

 

image.png.65c4eb3dfdba70b1edfcedccdaaec017.png

Edited by loudy000
update attachement

Share this post


Link to post
Share on other sites
loudy000
5 hours ago, BIGAL said:

Like Tharwat are you just hatching multiple plines, doing an inside parallel pline. or other options. What I am suggesting is the options may all be done already in lisp.

 

Ssget has multiple select filters that you can use and can be multiple of,  such as layer, all or all in a particular space model / layout.

 

 

Thanks @BIGAL 

Share this post


Link to post
Share on other sites
BIGAL

This is real quick and not very detailed and would normally have a front end to choose hatch pattern and scale etc but gives a result. You need to provide more detail. Do you want them different colors etc.

 


(defun c:qkhatch ( / ss  x)
(if (setq ss (ssget (list (cons 0 "lwpolyline"))))
(progn
(setvar 'hpname "Ansi31")
(setvar 'hpscale 2.0)
(repeat (setq x (sslength ss))
(command "-hatch" "S" (ssname ss (setq x (1- x))) "" "p" "" "" "" "")
)
)
)
)
(c:qkhatch)

Share this post


Link to post
Share on other sites
Roy_043

There is a variable, HPSEPARATE, that governs if the _Hatch commands creates separate hatches or not. So what BIGAL is doing can be done without Lisp code.

Share this post


Link to post
Share on other sites
loudy000

Thanks @BIGAL  for that it's not actually hatch command that i want to run for each poly line.

 

It's the code above 

(defun c:Test ( / ss)
  (if (setq ss (ssget "_:L" '((0 . "*POLYLINE"))))
     (command "_MAPCreateFeatureFromGeometry" ss "" "yes" "landuse" "")
    )
  (princ)
  )

so i tried to adopt it and i thought it should be similar, just different command, but for some reason it's not working. Thanks again for your help guys.

(defun c:qkhatch ( / ss  x)
(if (setq ss (ssget (list (cons 0 "lwpolyline"))))
(progn
(repeat (setq x (sslength ss))
(command "_MAPCreateFeatureFromGeometry" "Landuse MP" (ssname ss (setq x (1- x))) "yes" "" "" "")
)
)
)
)
(c:qkhatch)

 

Share this post


Link to post
Share on other sites
BIGAL

In your video the map select asks for you to pick the pline that’s where the ssname needs to go.

 

You may need to select the object before running the command. Try it above, on IPad so no test.

Share this post


Link to post
Share on other sites
loudy000

still not working :(

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...