Jump to content

Entmake Functions


Lee Mac

Recommended Posts

Lee,

 

Here a new one. Is there a way to rotate a lwpolyline with entmake after the polyline has been made or is this best left to selection set malipulation. I do not want to resort to a rotate command call. Selection set is not such a big deal, But I was just wondering if there is an entmake alternative.

 

Thanks

The Buzzard

Link to comment
Share on other sites

The rotate code is only available with text/inserts etc (group 51 as you may know). I believe you would have to calculate the resultant positions of the polyline vertices, and modify the definition, if you wanted to proceed this way.

 

But there are alternatives, for example, the vla-rotate function in VL.

 

And there is also the powerful vla-transformby if you wanted to get a bit mathematically pure about it:

 

(defun rotate (obj pt ang / RotationMatrix Vector)
 ;; Rotation by Matrix  ~  Lee Mac 

 (setq RotationMatrix (list (list (cos ang) (- (sin ang))  0.0)
                            (list (sin ang)    (cos ang)   0.0)
                            (list    0.0           0.0     1.0)))

 (setq Vector (mapcar (function -) pt (mxv RotationMatrix pt)))
 
 (vla-transformby obj
   (vlax-tmatrix
     (append
       (mapcar
         (function
           (lambda (r x) (append r (list x))))

         RotationMatrix Vector)
       
       '((0.0 0.0 0.0 1.0))))))

;; MXV Apply a transformation matrix to a vector -Vladimir Nesterovsky-
(defun mxv (m v)
 (mapcar '(lambda (r) (apply '+ (mapcar '* r v))) m))

Link to comment
Share on other sites

The rotate code is only available with text/inserts etc (group 51 as you may know). I believe you would have to calculate where the vertices of the polyline would end up, and modify the definition, if you wanted to proceed this way.

 

But there are alternatives, for example, the vla-rotate function in VL, and also the vla-transformby if you wanted to get a bit mathematically pure about it.

 

(defun rotate (obj pt ang / RotationMatrix Vector)
 ;; Rotation by Matrix  ~  Lee Mac 

 (setq RotationMatrix (list (list (cos ang) (- (sin ang))  0.0)
                            (list (sin ang)    (cos ang)   0.0)
                            (list    0.0           0.0     1.0)))

 (setq Vector (mapcar (function -) pt (mxv RotationMatrix pt)))

 (vla-transformby obj
   (vlax-tmatrix
     (append
       (mapcar
         (function
           (lambda (r x) (append r (list x))))

         RotationMatrix Vector)

       '((0.0 0.0 0.0 1.0))))))

;; MXV Apply a transformation matrix to a vector -Vladimir Nesterovsky-
(defun mxv (m v)
 (mapcar '(lambda (r) (apply '+ (mapcar '* r v))) m))

 

I have taken into consideration calculating the point locations. I would prefer to stick with an entmake option all the same. I shall see what I can come up with.

 

Thanks

Link to comment
Share on other sites

This would work using entmod to calculate where the new vertices will be:

 

(defun rotate (ent pt ang / RotationMatrix Vector)
 ;; LWPoly Rotation by Matrix  ~  Lee Mac 

 (setq RotationMatrix (list (list (cos ang) (- (sin ang))  0.0)
                            (list (sin ang)    (cos ang)   0.0)
                            (list    0.0           0.0     1.0)))

 (setq Vector (mapcar (function -) pt (mxv RotationMatrix pt)))

 (entmod
   (mapcar
     (function
       (lambda (x)
         (if (= 10 (car x))
           (cons 10 (mapcar '+ (mxv RotationMatrix (cdr x)) Vector)) x)))

     (entget ent))))

;; MXV Apply a transformation matrix to a vector -Vladimir Nesterovsky-
(defun mxv (m v)
 (mapcar '(lambda (r) (apply '+ (mapcar '* r v))) m))

Link to comment
Share on other sites

This would work using entmod to calculate where the new vertices will be:

 

(defun rotate (ent pt ang / RotationMatrix Vector)
 ;; LWPoly Rotation by Matrix  ~  Lee Mac 

 (setq RotationMatrix (list (list (cos ang) (- (sin ang))  0.0)
                            (list (sin ang)    (cos ang)   0.0)
                            (list    0.0           0.0     1.0)))

 (setq Vector (mapcar (function -) pt (mxv RotationMatrix pt)))

 (entmod
   (mapcar
     (function
       (lambda (x)
         (if (= 10 (car x))
           (cons 10 (mapcar '+ (mxv RotationMatrix (cdr x)) Vector)) x)))

     (entget ent))))

;; MXV Apply a transformation matrix to a vector -Vladimir Nesterovsky-
(defun mxv (m v)
 (mapcar '(lambda (r) (apply '+ (mapcar '* r v))) m))

 

 

Lee,

 

I thought it would be much less complcated, But I shall figure this one out.

 

Thanks again

Link to comment
Share on other sites

Lee,

 

I posted a message about a problem with a function, But deleted it soon after. I solved the problem due to a wrong input value.

Thanks anyway

Link to comment
Share on other sites

This will greatly help you understand its methods:

 

http://en.wikipedia.org/wiki/Rotation_matrix

 

 

Anyway Lee,

 

I figured out my own method, Not that there is anything wrong with the one you provided. I just did not think for the purpose of what I am trying to do that the addition of another function was really needed.

 

Here in this example I just swapped points and it works well. I am sure you will find things you may not like , So feel free to tear it apart. Its all good.

 

;/////////////////////////////////////////////////////////////////////////////
;
; Start-Up Function.
;
(defun C:COMPLEX ()
 (SAVE_USER_SETTINGS)
 (princ))
(princ "\nCOMPLEX.lsp loaded... Type Complex to start.")
;
;/////////////////////////////////////////////////////////////////////////////
;
; Save User Settings Function.
;
(defun SAVE_USER_SETTINGS (/ SUS)
 (setq SUS_LIST (list "cmdecho" "orthomode" "osmode" "blipmode" "clayer" "angbase" "angdir"))
 (setq SUS (mapcar 'getvar SUS_LIST))
 (setq TERR$ *error*)
 (setq *error* ERROR_TRAP)
 (GET_LTYP)
 (princ))
;
;/////////////////////////////////////////////////////////////////////////////
;
; Get Linetype Function.
;
(defun GET_LTYP (/ STRPT ENDPT RADIANS DEGREES LNAM LTNAM LCLR LTYP LWGT)
 (or L::UNIT (setq L::UNIT "I"))
 (or L::TNAM (setq L::TNAM "1"))
 (setvar "cmdecho" 0)(setvar "orthomode" 1)(setvar "osmode" (nth 2 SUS))(setvar "angbase" 0)(setvar "angdir" 0)
 (initget 8 "I U")
 (setq L::UNIT
   (cond
     ((getkword (strcat"\nSelect linetype standard; [<I>SO, <U>S] Default <"L::UNIT">: ")))
     (T L::UNIT)))
 (initget 8 "1 2 3 4")
 (setq L::TNAM
   (cond
     ((getkword (strcat"\nSelect linetype number; [<1> Batting, <2> Hot Water Supply, <3> Gas Line or <4> Zig zag] Default <"L::TNAM">: ")))
     (T L::TNAM)))
 (cond
   ((= L::TNAM "1")(setq LTNAM "BATTING"))
   ((= L::TNAM "2")(setq LTNAM "HOT_WATER_SUPPLY"))
   ((= L::TNAM "3")(setq LTNAM "GAS_LINE"))
   ((= L::TNAM "4")(setq LTNAM "ZIGZAG")))
 (if (not (tblsearch "LTYPE" LTNAM))
   (cond
     ((= L::UNIT "I")(command "._-linetype" "_load" LTNAM "acadiso.lin" ""))
     ((= L::UNIT "U")(command "._-linetype" "_load" LTNAM "acad.lin" ""))))
 (MAKE_LAYER)
 (princ))
;
;/////////////////////////////////////////////////////////////////////////////
;
; Make Layer Function.
;
(defun MAKE_LAYER ()
 (setq LNAM LTNAM LCLR 2 LTYP LTNAM LWGT 35)
 (if (null (tblsearch "layer" LNAM))
   (entmakex
     (list
       (cons 0   "LAYER")
       (cons 100 "AcDbSymbolTableRecord")
       (cons 100 "AcDbLayerTableRecord")
       (cons 2    LNAM)
       (cons 6    LTYP)
       (cons 62   LCLR)
       (cons 70   0)
       (cons 290  1)
       (cons 370  LWGT))))
 (MAKE_PLINE)
 (princ))
;
;/////////////////////////////////////////////////////////////////////////////
;
; Make Polyline Function.
;
(defun MAKE_PLINE ()
 (setq STRPT (getpoint "\nSpecify line starting point: "))
 (while
   (/= nil (setq ENDPT (getpoint STRPT "\nSpecify line ending point: ")))
   (setq RADIANS (angle STRPT ENDPT)
         DEGREES (RTD RADIANS))
   (if (and (> DEGREES 90)(<= DEGREES 270))
     (entmakex
       (list
         (cons 0 "LWPOLYLINE")
         (cons 100 "AcDbEntity")
         (cons 8 LNAM)
         (cons 100 "AcDbPolyline")
         (cons 90 2)
         (cons 70 0)
         (cons 10 ENDPT)
         (cons 10 STRPT))))
   (if (or (> DEGREES 270)(<= DEGREES 90))
     (entmakex
       (list
         (cons 0 "LWPOLYLINE")
         (cons 100 "AcDbEntity")
         (cons 8 LNAM)
         (cons 100 "AcDbPolyline")
         (cons 90 2)
         (cons 70 0)
         (cons 10 STRPT)
         (cons 10 ENDPT))))
   (setq STRPT ENDPT))
 (RESTORE_USER_SETTINGS)
 (princ))
;
;/////////////////////////////////////////////////////////////////////////////
;
; Degrees To Radians Function.
;
(defun DTR (DEGREES)(* pi (/ a 180.0)))
;
;/////////////////////////////////////////////////////////////////////////////
;
; Radians To Degrees Function.
;
(defun RTD (RADIANS)(* 180.0 (/ RADIANS pi)))
;
;/////////////////////////////////////////////////////////////////////////////
;
; Restore User Settings Function.
;
(defun RESTORE_USER_SETTINGS ()
 (setq *error* TERR$)
 (if SUS (mapcar 'setvar SUS_LIST SUS))
 (princ "\nProgram completed and will now restore the user settings and exit.")
 (princ))
;
;/////////////////////////////////////////////////////////////////////////////
;
; Error Trap Function.
;
(defun ERROR_TRAP (ERRORMSG)
 (command nil nil nil)
 (if (not (member ERRORMSG '("console break" "Function cancelled")))
   (princ (strcat "\nError:" ERRORMSG)))
 (if SUS (mapcar 'setvar SUS_LIST SUS))
 (princ "\nAttention!....A user error has occurred.")
 (princ "\nThe program will now restore the user settings and exit.")
 (terpri)
 (setq *error* TERR$)
 (princ))
;
;/////////////////////////////////////////////////////////////////////////////

Link to comment
Share on other sites

Anyway Lee,

 

I figured out my own method, Not that there is anything wrong with the one you provided. I just did not think for the purpose of what I am trying to do that the addition of another function was really needed.

 

Here in this example I just swapped points and it works well. I am sure you will find things you may not like , So feel free to tear it apart. Its all good.

 

 

Surely this would only work for rotations of pi?

Link to comment
Share on other sites

Surely this would only work for rotations of pi?

 

I did not need more than what you see. The other code will be handy when I get into something more complicated.

Link to comment
Share on other sites

Lee,

 

I was messing around with splines trying to get DXF data from them and noticed that the list size is not always the same. Depending on how its constructed can change all this.

 

So if I wanted to construct a dotted pair, How could a list be made to accomodate all this variation?

 

(-1 . <Entity name: 7ef65018>)
(0 . "SPLINE")
(330 . <Entity name: 7ef59cf8>)
(5 . "28B")
(100 . "AcDbEntity")
(67 . 0)
(410 . "Model")
(8 . "0")
(100 . "AcDbSpline")
(210 0.0 0.0 1.0)
(70 . 
(71 . 3)
(72 . 9)
(73 . 5)
(74 . 3)
(42 . 1.0e-010)
(43 . 1.0e-010)
(44 . 1.0e-010)
(40 . 0.0)
(40 . 0.0)
(40 . 0.0)
(40 . 0.0)
(40 . 3.79147)
(40 . 6.74976)
(40 . 6.74976)
(40 . 6.74976)
(40 . 6.74976)
(10 -12.9531 13.532 0.0)
(10 -11.7433 12.8785 0.0)
(10 -9.58959 11.7152 0.0)
(10 -9.50751 9.31821 0.0)
(10 -9.47153 8.26764 0.0)
(11 -12.9531 13.532 0.0)
(11 -9.9774 11.1824 0.0)
(11 -9.47153 8.26764 0.0)

Link to comment
Share on other sites

I assume that would mean providing additional calculations. I am just not sure what all the required values needed means. Some of the terms I never heard of, So how is one to write a calculation for some of these.

 

e.g. Knots, Control points, Fit points etc etc..

Link to comment
Share on other sites

I think its fair to say that you need to be mentally prepared for that.

I will just have to invest the time in it over the long haul and see where it goes.

 

 

Thanks

Link to comment
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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...