Author Topic: 2 questions about block  (Read 2351 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1422
2 questions about block
« on: February 06, 2013, 11:23:16 AM »
How to insert a block in a file
Code: [Select]
file path "c:\\GMC\\GM_Limits.dwg"
Blockname GM-Limits
(vla-insertblock doc ins_pt blk 1.0 1.0 1.0 0.0 )

I want to insert a block in round of number
Is there a better way for this
Code: [Select]
(setq ins_pt (vlax-3d-point (list (LM:Round (nth 0 ins_pt) 5) (LM:Round (nth 1 ins_pt) 5) 0.0)))
« Last Edit: February 07, 2013, 11:46:37 AM by CAB »

ronjonp

  • Needs a day job
  • Posts: 7531
Re: 2 questions avout block
« Reply #1 on: February 06, 2013, 11:31:48 AM »
I just got a picture of "The Count" in my head  :lmao:

To answer your question it looks like the code should be fine.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: 2 questions avout block
« Reply #2 on: February 06, 2013, 11:36:43 AM »
I just got a picture of "The Count" in my head  :lmao:
AHH AHHH AHHH AHHHHHH!!
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

ronjonp

  • Needs a day job
  • Posts: 7531
Re: 2 questions avout block
« Reply #3 on: February 06, 2013, 12:13:26 PM »
I just got a picture of "The Count" in my head  :lmao:
AHH AHHH AHHH AHHHHHH!!

 :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: 2 questions about block
« Reply #4 on: February 07, 2013, 09:43:27 AM »
This is the lisp

Code: [Select]
(defun c:gml ( / BLK BLK_NO CNT CORD_QNTY DOC E INS_PT ME_BLOCK MSG N OSM OSZ PRCL_N PRCL_NO SS
  )
  ; insert block and modify insertion point round of 5
  (vl-load-com)
  (defun *error* ( m ) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **")))
    (if (= 'int (type osz)) (setvar 'osnapz osz) ) (if (= 'int (type osm)) (setvar 'osmode osm) ) (princ))

  (if (= 0 (getvar "TILEMODE")) (setvar "TILEMODE" 1))

  (setq doc (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object) )))

  (if
    (setq blk (ssget "_X" '((0 . "INSERT") (2 . "Frame1") (66 . 1))))
    (progn
(setq blk (vlax-ename->vla-object (ssname blk 0)))
(if (setq osz (getvar 'osnapz)) (setvar 'osnapz 0))
(setq osm (getvar 'osmode))
(setvar 'osmode 8) (setq cnt 1)
(setq blk_no (getstring "\nWhat is Block No? "))
(LM:vl-SetAttributeValue blk "BLOCK" blk_no)
(setq prcl_no (getstring "\nWhat is Parcel No? "))
(setq cord_Qnty (getstring "\nHow many coordinate point for parcel? "))
(setq ins_p (getpoint "\nPick center of parcel: "))
(LM:vl-SetAttributeValue blk "BARCIL" prcl_no)
(setq ins_pt (vlax-3d-point (list (LM:Round (nth 0 ins_p) 5) (LM:Round (nth 1 ins_p) 5) 0.0)))
(if (not (tblsearch "BLOCK" "GM-Limits"))
  (progn
    (setq me_block (vla-insertblock doc ins_pt (strcat "c:\\GMC\\" "GM-Limits") 1.0 1.0 1.0 0.0 )))
  (setq me_block (vla-insertblock doc ins_pt "GM-Limits" 1.0 1.0 1.0 0.0 )))
(if (not (vlax-object-released-p me_block)) (vlax-release-object me_block))
(P_Txt prcl_no ins_p)     
        ) ;progn
        (princ "\nBlock ( Frame1 ) not found."))
      (setvar "TILEMODE" 0)
  (princ)
  )

(defun LM:vl-SetAttributeValue ( block tag value )
  ; Lee Mac, Copyright © 2010 - www.lee-mac.com
    (setq tag (strcase tag))
    (vl-some (function (lambda ( attrib ) (if (eq tag (strcase (vla-get-TagString attrib)))
                    (progn (vla-put-TextString attrib value) value)))) (vlax-invoke block 'GetAttributes))) ;defun LM:vl-SetAttributeValue

(defun LM:vl-SetAttributeValues ( block lst / pair )
    ; Lee Mac, Copyright © 2010 - www.lee-mac.com
    (foreach attrib (vlax-invoke block 'GetAttributes) (if (setq pair (assoc (strcase (vla-get-tagstring attrib)) lst))
            (vla-put-textstring attrib (cdr pair))))) ;defun LM:vl-SetAttributeValues

  (defun LM:Round (num dp / fac rm)
    (setq fac (float (expt 10 dp)) rm  (rem (setq num (* fac num)) 1))
    (/ (cond (  (zerop rm) (fix num)) (  (< 0.5 rm) (1+ (fix num))) (  (+ (/ 5 fac) (fix num)))) fac)) ;defun LM:Round

(defun P_Txt (str i_pt)
       (entmakex (list
    (cons 0 "TEXT") ;***
    (cons 1 (strcat "Parcel No. " str)) ;* (the string itself)
    (cons 6 "BYLAYER") ; Linetype name
            (cons 7 "STANDARD") ;* Text style name, defaults to STANDARD, not current
            (cons 8 "Site_Surrondings") ; layer
            (cons 10 i_pt) ;* First alignment point (in OCS)
    (cons 39 0.0) ; Thickness (optional; default = 0)
            (cons 40 2.0) ;* Text height
            (cons 41 1.0) ; Relative X scale factor, Width Factor, defaults to 1.0
            (cons 50 0.0) ; Text rotation ange
            (cons 51 0.0) ; Oblique angle
            (cons 62 256) ; color
            (cons 71 0) ; Text generation flags
            (cons 72 0) ; Horizontal text justification type
            (cons 73 2) ; Vertical text justification type
            (cons 210 (list 0.0 0.0 1.0)))))

(princ "\n:: GML.lsp | Version 1.0 | Type GML to invoke the lisp :")
« Last Edit: February 07, 2013, 11:46:55 AM by CAB »