Author Topic: please help with code  (Read 2112 times)

0 Members and 1 Guest are viewing this topic.

nekonihonjin

  • Newt
  • Posts: 103
please help with code
« on: August 16, 2014, 09:34:20 AM »
Hi everyone, I'm trying to make a lisp that would help me lots in work, I'm not very good at this so I advance slowly by trial and error, but now I'm stuck...

Please if someone can take a look at the code.  After the "foreach" function the points that was saved whit the entlast  (ptoelev2, ptocielo2,ptopiso2) the "rotate" and "move" functions won't recognize that variables....






Code: [Select]
(defun C:xgiro(/ angulo prim elev linea obj1 obj2)
(command "_filedia" "0" )
(command "_color" "_t" "255,0,0" )
(setq angulo (getstring "\nAngulo de giro: "))
(setq elev (car (entsel "\nLínea de elevación: ")))
(setq cielo (car (entsel "\n Polilínea de contracielo: ")))
(setq piso (car (entsel "\n Polilínea de piso: ")))
(setq elevgiro (car (entsel "\nLínea de elevación con giro: ")))


   (while

    (setq prim (getpoint "\nPunto en la planta de la obra: "))
    (command "_line" prim "@10<90" "")
    (setq linea (entlast))
    (command "_copy" linea "" "0,0,0" "0,0,0")
    (setq lineagiro  (entlast))
    (command "_rotate" lineagiro "" prim angulo)
                 
                 
     (setq ptoelev (foreach pnt (LM:Intersections (vlax-ename->vla-object linea) (vlax-ename->vla-object elev) acextendthisentity)
            (entmake (list '(0 . "POINT") (cons 10 pnt)))
        ))   
     

      (setq ptocielo (foreach pnt (LM:Intersections (vlax-ename->vla-object linea) (vlax-ename->vla-object cielo) acextendthisentity)
            (entmake (list '(0 . "POINT") (cons 10 pnt)))
        ))   


      (setq ptopiso (foreach pnt (LM:Intersections (vlax-ename->vla-object linea) (vlax-ename->vla-object piso) acextendthisentity)
            (entmake (list '(0 . "POINT") (cons 10 pnt)))
        ))
       


    (command "_point" ptoelev "")
    (setq ptoelev2 (entlast))
    (command "_point" ptocielo "")
    (setq ptocielo2 (entlast))
    (command "_point" ptopiso "")
    (setq ptopiso2 (entlast))
   
   
    (foreach pnt (LM:Intersections (vlax-ename->vla-object lineagiro) (vlax-ename->vla-object elevgiro) acextendthisentity)
            (entmake (list '(0 . "POINT") (cons 10 pnt)))
        )   
     (setq ptoelevgiro (entlast))



    (command "_rotate" ptoelev2 ptocielo2 ptopiso2 "" ptoelev angulo )
    (command "_move" ptoelev2 ptocielo2 ptopiso2 "" ptoelev ptoelevgiro)



(princ)

    ); end while

(command "_color" "_BYLAYER" )
(command "_filedia" "1" )
(princ)
)
(vl-load-com)(princ)



(defun LM:Intersections ( obj1 obj2 mode / l r )
    (setq l (vlax-invoke obj1 'intersectwith obj2 mode))
    (repeat (/ (length l) 3)
        (setq r (cons (list (car l) (cadr l) (caddr l)) r)
              l (cdddr l)
        )
    )
    (reverse r)
)

ribarm

  • Gator
  • Posts: 3312
  • Marko Ribar, architect
Re: please help with code
« Reply #1 on: August 16, 2014, 11:01:34 AM »
This line and next similar don't have sense...

Code: [Select]
     (setq ptoelev (foreach pnt (LM:Intersections (vlax-ename->vla-object linea) (vlax-ename->vla-object elev) acextendthisentity)
            (entmake (list '(0 . "POINT") (cons 10 pnt)))
        ))   

Instead try to make list of point entities like this line :

Code: [Select]
     (foreach pnt (LM:Intersections (vlax-ename->vla-object linea) (vlax-ename->vla-object elev) acextendthisentity)
         (setq ptoelev (cons (entmakex (list '(0 . "POINT") (cons 10 pnt))) ptoelev)
      )   
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

nekonihonjin

  • Newt
  • Posts: 103
Re: please help with code
« Reply #2 on: August 16, 2014, 11:26:25 AM »
thanks for the response, the code runs as you suggested, (a right parenthesis was missing, but nevermind) but still I'm unable to use the coordenates of the point that is created with this line...

this line it's suposed to hold a point named "ptoelev"  but after that if I want to use it for moving an entity using this point as the initial point, it does nothing  :cry:

Code: [Select]
(foreach pnt (LM:Intersections (vlax-ename->vla-object linea) (vlax-ename->vla-object elev) acextendthisentity)
         (setq ptoelev (cons (entmakex (list '(0 . "POINT") (cons 10 pnt))) ptoelev))
      )

     (foreach pnt (LM:Intersections (vlax-ename->vla-object linea) (vlax-ename->vla-object cielo) acextendthisentity)
            (setq ptocielo (cons (entmakex (list '(0 . "POINT") (cons 10 pnt))) ptocielo))
        )   


      (foreach pnt (LM:Intersections (vlax-ename->vla-object linea) (vlax-ename->vla-object piso) acextendthisentity)
            (setq ptopiso (cons (entmakex (list '(0 . "POINT") (cons 10 pnt))) ptopiso))
        )
       

 
   
     (foreach pnt (LM:Intersections (vlax-ename->vla-object lineagiro) (vlax-ename->vla-object elevgiro) acextendthisentity)
            (setq ptoelevgiro (cons (entmakex (list '(0 . "POINT") (cons 10 pnt))) ptoelevgiro))
        )
   


    (command "_rotate" ptoelev ptocielo ptopiso "" ptoelev angulo )
    (command "_move" ptoelev ptocielo ptopiso "" ptoelev ptoelevgiro)

here points are created at the intersection of lines as I want but the command rotate and move  do not work
« Last Edit: August 16, 2014, 11:29:32 AM by nekonihonjin »

ribarm

  • Gator
  • Posts: 3312
  • Marko Ribar, architect
Re: please help with code
« Reply #3 on: August 16, 2014, 12:25:28 PM »
Point entity list, selection set of entities or just a single entity name are 3 different things... You must decide which one is the most suitable for your task...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

nekonihonjin

  • Newt
  • Posts: 103
Re: please help with code
« Reply #4 on: August 16, 2014, 03:36:48 PM »
I was hoping that just the entity name, in order to move it, but as I said it wont work...

But perhaps you can tell what data I need, what I'm trying to achieve is this: I have a set of 3 lines one of them it's horizontal and represents the elevation, the remaining two are the representation of a tunnel (one the floor, the other the celling? (top)  ) it's a longitudinal section. And then I have this other line that also represents the same elevatión but it's not horizontal, it has an angle...

In the bottom of the drawing it's the top view, and it's from wich the lisp proyects a vertical line and places a point at the intersections with the first 3 lines...   Then that pruyected line is rotated to get perpendicular to the 4th line I named......  So far it's what the code can do...   But I need that 3 points that were created be moved to the intersection of the rotated proyected line with the 4th line (the elevation with angle)   and then rotated to fit the angle of that line...   


The attachment explains it better

ribarm

  • Gator
  • Posts: 3312
  • Marko Ribar, architect
Re: please help with code
« Reply #5 on: August 16, 2014, 04:38:51 PM »
Here, try this code and I hope you'll be satisfied...

Code: [Select]
(defun c:xgiro ( / osm horizontalelevationbottomline floorelevationline topelevationline angledelevationbottomline
                   p p1 p2 p3 anvec nanvec pan1 pan2 pan3 )

  (vl-load-com)

  (setq osm (getvar 'osmode))
  (setvar 'osmode 0)
  (setq horizontalelevationbottomline (car (entsel "\nPick horizontal elevation bottom line")))
  (setq floorelevationline (car (entsel "\nPick floor elevation polyline")))
  (setq topelevationline (car (entsel "\nPick top elevation polyline")))
  (setq angledelevationbottomline (car (entsel "\nPick angled elevation bottom line")))
 
  (setq p t)
  (while (setq p (getpoint "\nPick point inside polyline of main grid (ENTER or right click to finish)"))
    (setq p1 (vlax-curve-getclosestpointtoprojection horizontalelevationbottomline p '(0.0 1.0 0.0)))
    (setq p2 (vlax-curve-getclosestpointtoprojection floorelevationline p '(0.0 1.0 0.0)))
    (setq p3 (vlax-curve-getclosestpointtoprojection topelevationline p '(0.0 1.0 0.0)))
    (setq anvec (vlax-curve-getfirstderiv angledelevationbottomline 0.0))
    (setq nanvec (polar '(0.0 0.0 0.0) (+ (* 0.5 pi) (angle '(0.0 0.0 0.0) anvec)) 1.0))
    (setq pan1 (vlax-curve-getclosestpointtoprojection angledelevationbottomline p nanvec))
    (setq pan2 (polar pan1 (angle p pan1) (distance p1 p2)))
    (setq pan3 (polar pan1 (angle p pan1) (distance p1 p3)))
    (entmake (list '(0 . "POINT") (cons 10 p1)))
    (entmake (list '(0 . "POINT") (cons 10 p2)))
    (entmake (list '(0 . "POINT") (cons 10 p3)))
    (entmake (list '(0 . "POINT") (cons 10 pan1)))
    (entmake (list '(0 . "POINT") (cons 10 pan2)))
    (entmake (list '(0 . "POINT") (cons 10 pan3)))
  )
  (setvar 'osmode osm)
  (princ)
)

HTH, M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

nekonihonjin

  • Newt
  • Posts: 103
Re: please help with code
« Reply #6 on: August 16, 2014, 05:25:46 PM »
Excelent!! there's even no need of entering the angle... Thank you, very much.