add on vertex block or line

Discussion in 'AutoCAD' started by katarina, Jun 1, 2004.

  1. katarina

    katarina Guest

    HI,
    could you help me,
    I need lisp or something else you consider is better:
    I have polylines - not closed and I want to add to all vertex
    on polyline object (block or line), which is perpendicular to
    polyline.
    Katarina
     
    katarina, Jun 1, 2004
    #1
  2. katarina

    Jürg Menzi Guest

    Katarina

    Try this:

    (defun C:MarkVertices ( / CurEnt CurObj ExLoop)
    (vl-load-com)
    (while (not ExLoop)
    (initget " ")
    (setq CurEnt (entsel "\nSelect Polyline: "))
    (cond
    ((eq CurEnt "") (setq ExLoop T))
    (CurEnt
    (setq CurObj (vlax-ename->vla-object (car CurEnt)))
    (if (eq (vla-get-ObjectName CurObj) "AcDbPolyline")
    (setq ExLoop T)
    (princ (strcat "selected entity is not a Polyline. "))
    )
    )
    ((princ "1 selected, 0 found. "))
    )
    )
    (if CurObj (InsertAtVertex CurObj "MyBlock")) ;"MyBlock.dwg" if ext. Block
    (princ)
    )

    (defun InsertAtVertex (Obj Nme / ActDoc CurSpc CurPar InsAng PntLst TmpLst)
    (setq ActDoc (vla-get-ActiveDocument (vlax-get-acad-object))
    CurSpc (if (or
    (= (getvar "TILEMODE") 1)
    (> (getvar "CVPORT") 1)
    )
    (vla-get-ModelSpace ActDoc)
    (vla-get-PaperSpace ActDoc)
    )
    TmpLst (vlax-get Obj "Coordinates")
    )
    (while
    (setq PntLst (cons
    (list (car TmpLst) (cadr TmpLst) 0.0)
    PntLst
    )
    TmpLst (cddr TmpLst)
    )
    )
    (foreach Pnt (reverse PntLst)
    (setq CurPar (vlax-curve-getParamAtPoint Obj Pnt)
    InsAng (Vec2Ang (vlax-curve-getFirstDeriv Obj CurPar))
    )
    (vla-InsertBlock CurSpc (vlax-3d-point Pnt) Nme 1 1 1 InsAng)
    )
    )
    ;
    ; == Function WvpVec2Ang
    ; Converts a vector to an angle.
    ; Arguments [Type]:
    ; Vec = Vector value

    • ; Return [Type]:
      ; > Angle value [REAL]
      ; Notes:
      ; Credits to Luis Esquivel
      ;
      (defun Vec2Ang (Vec / XvcVal YvcVal)
      (setq XvcVal (car Vec)
      YvcVal (cadr Vec)
      )
      (cond
      ((equal XvcVal 0 1E-4) (if (minusp YvcVal) (* pi 1.5) Wv:pi2))
      ((equal XvcVal -1 1E-4) pi)
      ((equal YvcVal 0 1E-4) (if (minusp XvcVal) pi 0))
      (T (atan (/ YvcVal XvcVal)))
      )
      )

      Cheers
     
    Jürg Menzi, Jun 1, 2004
    #2
  3. katarina

    Jürg Menzi Guest

    Oops...

    Line:
    ((eq CurEnt "") (setq ExLoop T))
    must be:
    ((eq CurEnt "") (setq ExLoop T CurObj nil))

    Cheers
     
    Jürg Menzi, Jun 1, 2004
    #3
  4. katarina

    BillZ Guest

    Jurg:

    Excuse my ignorance.

    What is the Wv:pi2 in (if (minusp YvcVal) Wv:pi2)??

    Bill
     
    BillZ, Jun 1, 2004
    #4
  5. katarina

    Jürg Menzi Guest

    Bill
    A constant in my application environment...
    (/ pi 2)

    Thanks for pointing to my sloppy work...

    Cheers
     
    Jürg Menzi, Jun 1, 2004
    #5
  6. katarina

    Jürg Menzi Guest

    Hi Katarina

    Bill has found another mistake in my sample. Ok, third post:

    (defun C:MarkVertices ( / CurEnt CurObj ExLoop)
    (vl-load-com)
    (while (not ExLoop)
    (initget " ")
    (setq CurEnt (entsel "\nSelect Polyline: "))
    (cond
    ((eq CurEnt "") (setq ExLoop T CurObj nil))
    (CurEnt
    (setq CurObj (vlax-ename->vla-object (car CurEnt)))
    (if (eq (vla-get-ObjectName CurObj) "AcDbPolyline")
    (setq ExLoop T)
    (princ (strcat "selected entity is not a Polyline. "))
    )
    )
    ((princ "1 selected, 0 found. "))
    )
    )
    (if CurObj
    (InsertAtVertex CurObj "MyBlock") ;"MyBlock.dwg" if ext. Block
    )
    (princ)
    )

    (defun InsertAtVertex (Obj Nme / ActDoc CurSpc CurPar InsAng PntLst TmpLst)
    (setq ActDoc (vla-get-ActiveDocument (vlax-get-acad-object))
    CurSpc (if (or
    (= (getvar "TILEMODE") 1)
    (> (getvar "CVPORT") 1)
    )
    (vla-get-ModelSpace ActDoc)
    (vla-get-PaperSpace ActDoc)
    )
    TmpLst (vlax-get Obj "Coordinates")
    )
    (while
    (setq PntLst (cons
    (list (car TmpLst) (cadr TmpLst) 0.0)
    PntLst
    )
    TmpLst (cddr TmpLst)
    )
    )
    (foreach Pnt (reverse PntLst)
    (setq CurPar (vlax-curve-getParamAtPoint Obj Pnt)
    InsAng (Vec2Ang (vlax-curve-getFirstDeriv Obj CurPar))
    )
    (vla-InsertBlock CurSpc (vlax-3d-point Pnt) Nme 1 1 1 InsAng)
    )
    )
    ;
    ; == Function Vec2Ang
    ; Converts a vector to an angle.
    ; Arguments [Type]:
    ; Vec = Vector value

    • ; Return [Type]:
      ; > Angle value [REAL]
      ; Notes:
      ; Credits to Luis Esquivel
      ;
      (defun Vec2Ang (Vec / XvcVal YvcVal)
      (setq XvcVal (car Vec)
      YvcVal (cadr Vec)
      )
      (cond
      ((equal XvcVal 0 1E-4) (if (minusp YvcVal) (* pi 1.5) (* pi 0.5)))
      ((equal XvcVal -1 1E-4) pi)
      ((equal YvcVal 0 1E-4) (if (minusp XvcVal) pi 0))
      (T (atan (/ YvcVal XvcVal)))
      )
      )

      Cheers
     
    Jürg Menzi, Jun 1, 2004
    #6
  7. katarina

    BillZ Guest

    Jurg,

    That's okay as I'm looking to use this for something that I need here.

    Also: (T (atan (/ YvcVal XvcVal)))

    Does not work in all situations.

    (T (atan YvcVal XvcVal))
    Works perfectly as it delivers the minus figure, when it should.

    Bill
     
    BillZ, Jun 1, 2004
    #7
  8. katarina

    Jürg Menzi Guest

    Thanx Bill...

    Cheers
     
    Jürg Menzi, Jun 1, 2004
    #8
  9. katarina

    katarina Guest

    Hi,
    Thank you for all,
    I will try it.
    Katarina
     
    katarina, Jun 2, 2004
    #9
  10. katarina

    katarina Guest

    Hi,
    it is working very good.
    Thank you again
    Katarina
     
    katarina, Jun 2, 2004
    #10
  11. katarina

    Jürg Menzi Guest

    Hi Katarina

    Glad to help you...

    Cheers
     
    Jürg Menzi, Jun 2, 2004
    #11
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.