vla-get-startangle issues

vla-get-startangle issues

Anonymous
Not applicable
1,408 Views
10 Replies
Message 1 of 11

vla-get-startangle issues

Anonymous
Not applicable

I am trying to use AutoLISP to grab some elements in yet another block and assign them to layers.  I have my LISP grabbing polylines and splines successfully, but the ellipsi are proving elusive.  

 

I know the commands I need to use are vla-get-startangle and vla-get-endangle, but I cannot get it to work right.

 

I've attached a dwg with a block that I need the LISP to process.  Also included are two LISPS, one that correctly assigns the splines and polylines ("GOOD SO FAR"), and the other is my unsuccessful attempt at dealing with the ellipsi.

 

The second LISP always halts with the block editor open, that's as far as I can get.  Can someone enlighten me?  Thanks in advance for any help!

0 Likes
Accepted solutions (1)
1,409 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable

I just remembered that the degrees need to be in radians...but I still cant get the darn overall LISP to cooperate.  It always stops with the block editor open and not everything has been moved to the right layers.

 

Now I have 2 separate files, one that works on just the ellpsi, and one on everything else.  ARRRGH!  Is there some obscure rule about mixing vla with vlax functions, maybe??

0 Likes
Message 3 of 11

Kent1Cooper
Consultant
Consultant

Quick thought --

 

It may be that the returned start and end angles are not precisely the values you're looking for, but may be off by a tiny bit too small to show in display precision, way down at the 13th decimal place or something.  Try using the (equal) function with a small fuzz factor, rather than the (=) function which requires exact equality.

 

 (equal (vla-get-StartAngle b) 272.5 1e-6) ; [or rather its radians equivalent]

 

and likewise for the end angle.

Kent Cooper, AIA
Message 4 of 11

Anonymous
Not applicable

Nope, unfortunately that didn't work.

 

I can get the code to select the ellipsi easily enough for now by using a "greater than" expression...but...the very instant I try and use the exact same ellipse code (below) in a LISP where I'm also trying to grap polylines and splines (that works fine w/o ellipse code) the routine freezes with the block editor opened.

 

 

Ellipse code:

 

(if (and
(> (vla-get-StartAngle b) 4.71239 1e-6)
(> (vla-get-EndAngle b) 4.71239 1e-6)
)
;;the object is an ellipse with spec'd start and end angles
(addprop b "HILMOT-MDR")
;; then add to this layer

0 Likes
Message 5 of 11

Ranjit_Singh
Advisor
Advisor

I am not sure if I understand the question entirely. But I was able to use the below changed code and it adds all ellipses to the right layer

Spoiler

;;*************************      {  ADD BLOCK PROPERTIES  }       ****************************;;
;;                                                                                            ;;
;;       ------------------  Designed & Created by Satish Rajdev  ------------------          ;;
;;                                                                                            ;;
;;       ------------------  Command to Invoke = "crl"            ------------------          ;;
;;                                                                                            ;;
;;       This program as written by Satish colors ONLY the roller and sensor lines            ;;
;;********************************************************************************************;;

(defun c:CRVCLR2 (/      setz   addprop       mid    getconn       sortlist
              removedup     cmd    nm     bks    bkl    i      bk
              a      b      c      d      e      e1     e2     e3
             )
  (vl-load-com)

  ;;********************************************************************************************;;
  ;;****************************************  UTILITIES ****************************************;;
  ;;********************************************************************************************;;

  (defun *error* (msg)
    (if (not
          (wcmatch (strcase msg t) "*break,*cancel*,*exit*")
        )
      (progn
        (princ "")
        (setvar 'nomutt nm)
        (setvar 'cmdecho cmd)
        (vla-endundomark
          (vla-get-activedocument (vlax-get-acad-object))
        )
      )
    )
    (princ)
  )
  ;;set error trapping here
  (defun setz (pnt)
    (list (car pnt) (cadr pnt))
    ;;remove elevation from the start or end point
  )
  (defun addprop (obj layer)
    (vla-put-color obj 256)
    ;;put color to bylayer
    (vla-put-layer obj layer)
    ;;put in the layer specifed
  )
  (defun removedup (l)
    (if l
      (cons (car l) (removedup (vl-remove (car l) (cdr l))))
      ;;removing duplicate element from the list
    )
  )

  ;;********************************************************************************************;;
  ;;**************************************  MAIN PROGRAM ***************************************;;
  ;;********************************************************************************************;;

  (if (setq bks (ssget '((0 . "insert"))))
    ;;select block on screen
    (progn
      (vla-startundomark
        (vla-get-activedocument (vlax-get-acad-object))
      )
      ;;setting the undo mark
      (setq cmd (getvar 'cmdecho)
            nm  (getvar 'nomutt)
      )
      (setvar 'cmdecho 0)
      ;;hiding command window
      (setvar 'nomutt 1)
      ;;hiding other command details
      (mapcar '(lambda (x y)
                 (if (not (tblsearch "layer" x))
                                        ;verifies layer are present or not
                   (entmakex (list
                               '(0 . "layer")
                               (cons 100 "AcDbSymbolTableRecord")
                               (cons 100 "AcDbLayerTableRecord")
                               (cons 2 x)
                               (cons 70 0)
                               (cons 62 y)
                               (cons 6 "Continuous")
                             )
                   )
                 )
                 ;;creating layer
               )
              (list "HILMOT-ROLLERS"
                    "HILMOT-FRAMES"
                    "HILMOT-MDR"
                    "HILMOT-SENSORS"
      "HILMOT-DRIVE CARDS"
      "HILMOT-ARROWS"
              )
              ;;layer list
              (list 8 4 3 1 5 4)
              ;;color code for the layers
      )

      (repeat (setq i (sslength bks))
        ;;setting the repeat count
        (setq bkl
               (cons
                 (cdr (assoc 2 (entget (ssname bks (setq i (1- i))))))
                 bkl
               )
        )
        ;;getting the selected block list
      )
      (setq bkl (removedup bkl))
      ;;removing duplicate names of block
      (foreach bk bkl
        ;;running code for every block
        (setq c  nil
              d  nil
              ar nil
        )
        (command "-bedit" bk)
        ;;opening block editor
        (if (setq a (ssget "_x" '((0 . "spline,ellipse,*polyline"))))
          ;;selecting all splines, plines and ellipsi inside block in block editor
          (progn
            (repeat (setq i (sslength a))
              (setq
                b (vlax-ename->vla-object (ssname a (setq i (1- i))))
              )
   (cond
             ((and
                    (not (vlax-curve-isclosed b))
                    (< (vla-get-length b) 2.5)
                  )
                  ;;the object is not closed and has length less than 2.5"
                  (addprop b "HILMOT-SENSORS")
                  ;; then add to this layer
       )
    ((and
                    (vlax-curve-isclosed b)
                    (> (vla-get-area b) 10)
                  )
                  ;;the object is closed and has area greater than 10"
                  (addprop b "HILMOT-FRAMES")
                  ;; then add to this layer
  )
  (T
                  ;;the object is an ellipse with spec'd start and end angles
                  (addprop b "HILMOT-MDR")
                  ;; then add to this layer
       )
           )
     )
          );; progn

         (princ "\nTHIS IS A SPECIAL TEST MESSAGE.  Nothing changed.")    ;optional else clause
        );; if
        (vl-cmdf "_.bclose" "_sav")
        ;;closing block editor
        (initcommandversion)
      )
      ;; foreach
      (setvar 'nomutt nm)
      (setvar 'cmdecho cmd)
      ;;restoring the variables again
      (vla-endundomark
        (vla-get-activedocument (vlax-get-acad-object))
      )
      ;;ending the undo mark
    )
    ;; progn
  )
  ;; if
  (princ)
)
(vl-load-com)
(princ)
(princ
  (strcat
    "\n:: Add Block Properties.lsp ::"
    "\n:: Created by Satish Rajdev | "
    (menucmd "M=$(edtime,$(getvar,date),DDDD\",\" D MONTH YYYY)"
    )
    " ::"
    "\n:: Type \"crl\" to Invoke ::"
  )
)
(princ)

Message 6 of 11

Anonymous
Not applicable

A "T" solution is not a complete answer to my goal.  I should have been more upfront about that, my bad.

 

In the final, ultimate result, only certain ellipsi will go on that MDR layer, so I need to hard-code in the start and end angles of those particular ellipsi.  Then, the rest would be applicable to a "T" condition.

 

The degree values (both startangle and and endangIe) need to be on the MDR layer are 297.5 degrees and 342.5 degrees.  Again, sorry to anyone reading this thread, I should have been more complete in my initial request.

0 Likes
Message 7 of 11

Ranjit_Singh
Advisor
Advisor

OK. Try the below. The block updated correctly but misses the ellipses, this is because all the ellipses have startangle and endangle very different from 297.5 and 342.5.

 

Command: (vla-get-EndAngle b)
11.1265
Command: (vla-get-startAngle b)
4.84329

 

The below code will catch ellipses with start and end angle of 297.5 and 342.5. This, however, does not apply to the block you posted.

 

Spoiler

;;*************************      {  ADD BLOCK PROPERTIES  }       ****************************;;
;;                                                                                            ;;
;;       ------------------  Designed & Created by Satish Rajdev  ------------------          ;;
;;                                                                                            ;;
;;       ------------------  Command to Invoke = "crl"            ------------------          ;;
;;                                                                                            ;;
;;       This program as written by Satish colors ONLY the roller and sensor lines            ;;
;;********************************************************************************************;;

(defun c:CRVCLR2 (/      setz   addprop       mid    getconn       sortlist
              removedup     cmd    nm     bks    bkl    i      bk
              a      b      c      d      e      e1     e2     e3
             )
  (vl-load-com)

  ;;********************************************************************************************;;
  ;;****************************************  UTILITIES ****************************************;;
  ;;********************************************************************************************;;

  (defun *error* (msg)
    (if (not
          (wcmatch (strcase msg t) "*break,*cancel*,*exit*")
        )
      (progn
        (princ "")
        (setvar 'nomutt nm)
        (setvar 'cmdecho cmd)
        (vla-endundomark
          (vla-get-activedocument (vlax-get-acad-object))
        )
      )
    )
    (princ)
  )
  ;;set error trapping here
  (defun setz (pnt)
    (list (car pnt) (cadr pnt))
    ;;remove elevation from the start or end point
  )
  (defun addprop (obj layer)
    (vla-put-color obj 256)
    ;;put color to bylayer
    (vla-put-layer obj layer)
    ;;put in the layer specifed
  )
  (defun removedup (l)
    (if l
      (cons (car l) (removedup (vl-remove (car l) (cdr l))))
      ;;removing duplicate element from the list
    )
  )

  ;;********************************************************************************************;;
  ;;**************************************  MAIN PROGRAM ***************************************;;
  ;;********************************************************************************************;;

  (if (setq bks (ssget '((0 . "insert"))))
    ;;select block on screen
    (progn
      (vla-startundomark
        (vla-get-activedocument (vlax-get-acad-object))
      )
      ;;setting the undo mark
      (setq cmd (getvar 'cmdecho)
            nm  (getvar 'nomutt)
      )
      (setvar 'cmdecho 0)
      ;;hiding command window
      (setvar 'nomutt 1)
      ;;hiding other command details
      (mapcar '(lambda (x y)
                 (if (not (tblsearch "layer" x))
                                        ;verifies layer are present or not
                   (entmakex (list
                               '(0 . "layer")
                               (cons 100 "AcDbSymbolTableRecord")
                               (cons 100 "AcDbLayerTableRecord")
                               (cons 2 x)
                               (cons 70 0)
                               (cons 62 y)
                               (cons 6 "Continuous")
                             )
                   )
                 )
                 ;;creating layer
               )
              (list "HILMOT-ROLLERS"
                    "HILMOT-FRAMES"
                    "HILMOT-MDR"
                    "HILMOT-SENSORS"
      "HILMOT-DRIVE CARDS"
      "HILMOT-ARROWS"
              )
              ;;layer list
              (list 8 4 3 1 5 4)
              ;;color code for the layers
      )

      (repeat (setq i (sslength bks))
        ;;setting the repeat count
        (setq bkl
               (cons
                 (cdr (assoc 2 (entget (ssname bks (setq i (1- i))))))
                 bkl
               )
        )
        ;;getting the selected block list
      )
      (setq bkl (removedup bkl))
      ;;removing duplicate names of block
      (foreach bk bkl
        ;;running code for every block
        (setq c  nil
              d  nil
              ar nil
        )
        (command "-bedit" bk)
        ;;opening block editor
        (if (setq a (ssget "_x" '((0 . "spline,ellipse,*polyline"))))
          ;;selecting all splines, plines and ellipsi inside block in block editor
          (progn
            (repeat (setq i (sslength a))
              (setq
                b (vlax-ename->vla-object (ssname a (setq i (1- i))))
              )
   (cond
             ((and
                    (not (vlax-curve-isclosed b))
                    (< (vla-get-length b) 2.5)
                  )
                  ;;the object is not closed and has length less than 2.5"
                  (addprop b "HILMOT-SENSORS")
                  ;; then add to this layer
       )
    ((and
                    (vlax-curve-isclosed b)
                    (> (vla-get-area b) 10)
                  )
                  ;;the object is closed and has area greater than 10"
                  (addprop b "HILMOT-FRAMES")
                  ;; then add to this layer
  )
((and
                    (= (vla-get-StartAngle b) 272.5)
                    (= (vla-get-EndAngle b) 342.5)
   )
(addprop b "HILMOT-MDR"))
  (T "Need to catch some more true false conditions"
                 
       )
           )
     )
          );; progn

         (princ "\nTHIS IS A SPECIAL TEST MESSAGE.  Nothing changed.")    ;optional else clause
        );; if
        (vl-cmdf "_.bclose" "_sav")
        ;;closing block editor
        (initcommandversion)
      )
      ;; foreach
      (setvar 'nomutt nm)
      (setvar 'cmdecho cmd)
      ;;restoring the variables again
      (vla-endundomark
        (vla-get-activedocument (vlax-get-acad-object))
      )
      ;;ending the undo mark
    )
    ;; progn
  )
  ;; if
  (princ)
)
(vl-load-com)
(princ)
(princ
  (strcat
    "\n:: Add Block Properties.lsp ::"
    "\n:: Created by Satish Rajdev | "
    (menucmd "M=$(edtime,$(getvar,date),DDDD\",\" D MONTH YYYY)"
    )
    " ::"
    "\n:: Type \"crl\" to Invoke ::"
  )
)
(princ)

Message 8 of 11

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... 

(if (and
(> (vla-get-StartAngle b) 4.71239 1e-6)
(> (vla-get-EndAngle b) 4.71239 1e-6)
)
 ....


It may not matter, but if you're going to use the (>) function instead of (equal), there is no fuzz factor argument.  I say it may not matter [in this case] because with more than two arguments, it checks whether every one is greater than the next one, and 4.7ish is certainly greater than 10-to-the-minu-6 [isn't just about everything?].  But for future reference, you don't get a fuzz factor in (>).

Kent Cooper, AIA
Message 9 of 11

Kent1Cooper
Consultant
Consultant

It seems there's a significant difference between what is called "Start angle" in the Properties box and the StartAngle VLA Property, and likewise between what's called "End angle" and the EndAngle Property.  For closed Ellipses like those in your sample drawing, the former shows the same value for both start and end, but the VLA Property values are quite different not just in being in radians rather than degrees, but different from each other [I'm not sure exactly what they represent].

 

Could it be that you should be making some other test?  If you want only those at a particular angle or in a particular range of angles, either the (assoc 11) value in entity data or the MajorAxis VLA Property is the major axis endpoint location relative to the center [which is (assoc 10) or the Center property].  So I think the angle whose tangent [AutoLisp (atan) function] is the Y coordinate of that value divided by its X coordinate would give you the rotation direction of the major axis of an Ellipse.

Kent Cooper, AIA
Message 10 of 11

Anonymous
Not applicable

Thanks for all the help everyone.  I have some other fires to put out before I can get back to your many helpful suggestions.

0 Likes
Message 11 of 11

Anonymous
Not applicable
Accepted solution

I ended up paying a developer to write code for me.  His solution grabs the ellipses that touch the lines which get colored the same.  

0 Likes