Hi Aaryan,
Here you go with what I think works well.
;;; ==========================================================================
;;; E_Insert - adapted from the swamp [ ABLKInsert ]
;;; place block with Emake instead of command INSERT
;;; usage: (E_Insert BlockName InsPunt insLayer )
;;; -
;;; these may have a preset value, which will be used and reset to nil:
;;; E_InsPt E_rAng E_dAng E_Color E_Scale
;;; ==========================================================================
(defun E_Insert (BlockName E_InsPt E_InsLay / Ename NextEnt Data Attdefs Attblk pt10 pt11)
(setq E_InsPt (ifnot E_InsPt '(0 0) E_InsPt)
E_rAng (if E_rAng ; wordt nil gemaakt aan einde
E_rAng
(if E_dAng ; E_dAng = angel in degrees.
(deg_rad E_dAng)
0
)
)
E_Color (ifnot E_Color 256) ; wordt nil gemaakt aan einde
E_Scale (ifnot E_Scale 1.0) ; wordt nil gemaakt aan einde
E_InsLay (ifnot E_InsLay (getvar "clayer"))
)
;; alleen als het block al bestaat ....
(cond ((setq Ename (tblobjname "block" BlockName)) ; tblsearch
;; get Parent entity name
(setq NextEnt (entnext Ename))
;; first sub entity
(while NextEnt
;; get ATTDEF subentities
(setq Data (entget NextEnt))
(if (= "ATTDEF" (cdr (assoc 0 Data)))
(setq Attdefs (cons Data Attdefs))
)
(setq NextEnt (entnext NextEnt))
)
(setq Attblk (if (= nil attdefs)
0
1
)
) ;(pri "attdefs")
(and (entmake ;; entmake insert
(list '(0 . "INSERT")
'(100 . "AcDbBlockReference")
(cons 8 E_InsLay) ; layer name
(cons 66 Attblk)
(cons 2 BlockName)
(cons 10 E_InsPt) ; Insert Point
(cons 41 E_Scale)
(cons 42 E_Scale)
(cons 43 E_Scale)
(cons 50 E_rAng) ; Rotation angle default = 0
(cons 62 E_Color) ; E_Color 256 = bylayer
)
)
(foreach x (reverse Attdefs)
;; voor de atributen met FIT alignments....
(setq pt10 (plusXY (cdr (assoc 10 x)) E_InsPt))
(setq pt11 (plusXY (cdr (assoc 11 x)) E_InsPt))
;; entmake ATTRIBs based on ATTDEFS
(entmake (list '(0 . "ATTRIB")
(assoc 8 x)
(cons 10 pt10)
(assoc 40 x)
(assoc 1 x)
(assoc 50 x)
(assoc 41 x)
(assoc 51 x)
(assoc 7 x)
(assoc 71 x)
(assoc 72 x)
(cons 11 pt11)
(assoc 2 x)
(assoc 70 x)
(assoc 73 x)
(assoc 74 x)
)
)
)
(entmake '((0 . "SEQEND") (8 . "0"))) ; entmake SEQEND
)
)
(t nil)
)
(setq ent (entlast)
E_InsPt nil
E_rAng nil
E_dAng nil
E_Color nil
E_Scale nil
)
)
;; ==========================================================================
;; used routine.. (cause i sometimes forget how mapcar works)
(defun Plusxy (p disp / p3) ; ipv polar mag 2D en 3D zijn.
(setq p3 (mapcar '+ p disp)) ; telt afstand (x,y,z) op bij punt (x,y,z)
)
;; littlebit shorter if nil check function
(defun ifnot (def new /)
(if def
def
new
)
)
(defun deg_rad (fDeg) (/ (* fDeg pi) 180))
some words may look funny, they are not! I am Dutch.
Hope this works for you, even if it was a while.
the trick is probably what I did with pt10 and pt11, check it out.
And of cause, after this 'insert', you still need to fill the Attributes.