Author Topic: Understanding "entmake", "cons" & 'Trans" functions.  (Read 1471 times)

0 Members and 1 Guest are viewing this topic.

Cuddles

  • Guest
Understanding "entmake", "cons" & 'Trans" functions.
« on: December 18, 2014, 05:17:44 PM »
Hello to all,

I am currently building a "slot" function to draw, as the function name describes, a slot!

However, I'm having trouble creating the centre lines of the slot. I wish to use the entmake function to do so but do not fully understand how to construct the list in which entmake reads to draw the objects. I know there are a few threads on the site discussing such topic and am currently reading my way through them, but I'm finding it hard to understand.

The code for my "slot" function below. This is tested but keep in mind it's still under development.

Code: [Select]
;; *** MAIN FUNCTION ***
(defun c:SLOT (/ bpt1 bpt2 lgth wth1 ang1 ang2 ang3 rad1 dst1 dst2 pnt1
pnt2 pnt3 pnt4 pnt5 pnt6 pnt7 oldLay scmde)

;; NOTE TO SELF: Need error handler!

;; Function calls
(setup)
(Inputs)
(deg2Rad)
(calcPoints)
(drawSlot)
(reset)
(princ)
)

;; SETUP FUNCTION
(defun setup ()
(setq scmde (getvar "CMDECHO"))
(princ "\nSlot Program")
(setvar "CMDECHO" 0)
)

;; USER INPUTS
(defun Inputs ()
(setq bpt1 (getpoint "\nSpecify Base Point of Slot: "))
(setq bpt2 (getpoint "\nSpecify Length & Direction of Slot: " bpt1))
(setq wth1 (getdist "\nSpecify Width of Slot: "))
)

;; DEGREES TO RADIANS
(defun deg2Rad ()
(setq ang1 (/ pi 180))
)

;; CALCULATE POINTS & GEOMETRY
(defun calcPoints ()
;; Calculate geometry
(setq lgth (- (distance bpt1 bpt2) wth1)
  rad1 (/ wth1 2)
  dst1 (sqrt (+ (expt rad1 2) (expt rad1 2)))
  ;;  Angle of rotation from x-axis.
  ang2 (angle bpt1 bpt2)
)
;; Define points of slot
;; NOTE: angles are written in degrees and converted to radians
(setq pnt1 (polar bpt1 (+ (* 45 ang1) ang2) dst1)
  pnt2 (polar pnt1 ang2 lgth)
  pnt3 (polar pnt2 (+ (* 270 ang1) ang2) wth1)
  pnt4 (polar pnt3 ang2 (- lgth))
)
;; Define centre points of arc's (pnt5 & pnt6) and slot (pnt7)
(setq pnt5 (polar bpt1 ang2 rad1)
  pnt6 (polar pnt5 ang2 lgth)
  pnt7 (polar pnt5 ang2 (/ lgth 2))
)
;; Pass ang2 to ang3, create dst2
(setq ang3 ang2)
(setq dst2 (+ rad1 2))
)

;; DRAW SLOT AND CENTRE LINES
(defun drawSlot ()
;; Construct slot with polyline
(setq oldLay (getvar "CLAYER"))
(command "_.LAYER" "_Make" "TCL10 parts" "_Color" "2" "" "_LWeight" "0.3" "" "LTYPE" "Continuous" "" "_Plot" "P" "" "")
(command "PLINE" pnt1 pnt2 "A" pnt3 "L" pnt4 "A" "CL")

;; Construct centrelines at arc centre points
(command "_.LAYER" "_Make" "TCL03 centre" "_Color" "1" "" "_LWeight" "0.09" "" "LTYPE" "CENTER2" "" "_Plot" "P" "" "")
(repeat 2
(entmake
(list
   '(0 . "LINE")
(cons 10 (trans (polar pnt5 ang3 dst2) 1 0))
(cons 11 (trans (polar pnt5 ang3 (- dst2)) 1 0))
)
)
(setq ang3 (+ ang3 (/ pi 2.0))
  dst2 (- dst2)
)
)
(command "_.LAYER" "Set" oldLay "")
)

;; RESET FUNCTION
(defun reset ()
(setvar "CMDECHO" scmde)
(princ "\nSlot Program Complete")
(princ)
)

In the "draw slot and centre lines" subfunction, you can see the list currently being used. This draws centre lines at pnt5 only, but i also wish for it to draw centre lines at pnt6 as well. I'm unsure about how to add to this list for entmake to draw the centre lines at both pnt5 and pnt6.

The "entmake" function in my code came from a program created by Lee Mac and has been adapted to suit. I don't fully understand how the "cons" and "trans" functions work and am currently reading up on these, but again, struggling to understand.

If someone could explain to me the operation of the "cons" and "trans" functions, or direct me to a page explaining them, would be much appreciated.
Also, advice on list construction in regards to the entmake function would be appreciated also.

Lastly, if someone could also explain the numbers in front of the "cons" function - what they mean, how they work etc... I know they are something to do with DXF groups. Again, trying to find a source i can understand.

Many thanks,

Cuddles
« Last Edit: December 18, 2014, 07:43:14 PM by Cuddles »