Results 1 to 5 of 5

Thread: Correct me ! Query

  1. #1
    Member
    Join Date
    2011-10
    Posts
    40

    Default Correct me ! Query

    hello all,

    Can you please guide me in this code. i write few codes to place block at point entity.

    as i used "entsel ". it only allow to pick points not crossed window selection. below is my code. please dont give me link to download another lisp. i just write it using help file of AutoCAD. i want to know how can i do it in my lisp. there are several option on net to do so. but please guide me on this code.
    keep in mind i am not expert in lisp
    Code:
     
    (defun c:bh1()
    (setvar "OSMODE" 8)
    (setq a (entsel "pick object"))
    (setq b (cadr a))
    (command "-insert" "BH" b "" "" "" "" "" "")
    )

  2. #2
    I could stop if I wanted to Tharwat's Avatar
    Join Date
    2010-06
    Posts
    478

    Default Re: Correct me ! Query

    Something like this ..... ?

    Code:
    (defun c:TesT (/ ent)
      ;; Tharwat 12. Oct. 2011 ;;
      (if (and (setq ent (entsel "\n Select an entity :"))
               (member (cdr (assoc 0 (entget (car ent))))
                       '("LWPOLYLINE" "POLYLINE"   "LINE"
                         "SPLINE"     "XLINE"      "CIRCLE"
                         "ARC"
                        )
               )
               (tblsearch "BLOCK" "BH")
          )
        (entmakex
          (list '(0 . "INSERT")
                (cons 2 "BH")
                (cons 10
                      (vlax-curve-getclosestpointto (car ent) (cadr ent))
                )
                '(41 . 1.)
                '(42 . 1.)
                '(43 . 1.)
                '(50 . 0.)
          )
        )
        (princ)
      )
      (princ)
    )
    Tharwat

  3. #3
    I could stop if I wanted to Lee Mac's Avatar
    Join Date
    2009-03
    Location
    London, England
    Posts
    280

    Default Re: Correct me ! Query

    If I have correctly understood your intentions, I think this would be suitable:

    Code:
    (defun c:test ( / *error* block i sel vars vals )
        
        (defun *error* ( msg )
            (if vals (mapcar 'setvar vars vals))
            (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
                (princ (strcat "\nError: " msg))
            )
            (princ)
        )
    
        (while
            (not
                (or
                    (eq "" (setq block (getstring t "\nSpecify Block to Insert: ")))
                    (tblsearch "BLOCK" block)
                    (setq block (findfile (strcat block ".dwg")))
                )
            )
            (princ "\nBlock not found.")
        )
    
        (if
            (and
                (/= "" block)
                (setq sel (ssget '((0 . "POINT"))))
            )
            (progn
                (setq vars '("CMDECHO" "OSMODE" "ATTREQ")
                      vals  (mapcar 'getvar vars)
                )
                (mapcar 'setvar vars '(0 0 0))
                (repeat (setq i (sslength sel))
                    (command "_.-insert" block "_S" 1.0 "_R" 0.0
                        (trans (cdr (assoc 10 (entget (ssname sel (setq i (1- i)))))) 0 1)
                    )
                )
                (mapcar 'setvar vars vals)
            )
        )
        (princ)
    )
    Ask if you need any part of the code explained.
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?
    Just another Swamper

  4. #4
    Member
    Join Date
    2011-10
    Posts
    40

    Default Re: Correct me ! Query

    hey i used this code in my drawings. Can you make me explain it to me?


    Quote Originally Posted by Lee Mac View Post
    If I have correctly understood your intentions, I think this would be suitable:

    Code:
    (defun c:test ( / *error* block i sel vars vals )
     
        (defun *error* ( msg )
            (if vals (mapcar 'setvar vars vals))
            (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
                (princ (strcat "\nError: " msg))
            )
            (princ)
        )
     
        (while
            (not
                (or
                    (eq "" (setq block (getstring t "\nSpecify Block to Insert: ")))
                    (tblsearch "BLOCK" block)
                    (setq block (findfile (strcat block ".dwg")))
                )
            )
            (princ "\nBlock not found.")
        )
     
        (if
            (and
                (/= "" block)
                (setq sel (ssget '((0 . "POINT"))))
            )
            (progn
                (setq vars '("CMDECHO" "OSMODE" "ATTREQ")
                      vals  (mapcar 'getvar vars)
                )
                (mapcar 'setvar vars '(0 0 0))
                (repeat (setq i (sslength sel))
                    (command "_.-insert" block "_S" 1.0 "_R" 0.0
                        (trans (cdr (assoc 10 (entget (ssname sel (setq i (1- i)))))) 0 1)
                    )
                )
                (mapcar 'setvar vars vals)
            )
        )
        (princ)
    )
    Ask if you need any part of the code explained.

  5. #5
    I could stop if I wanted to Lee Mac's Avatar
    Join Date
    2009-03
    Location
    London, England
    Posts
    280

    Default Re: Correct me ! Query

    Quote Originally Posted by sanrajbhar677632 View Post
    Can you make me explain it to me?
    Which part do you not understand?
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?
    Just another Swamper

Similar Threads

  1. Object query?
    By patricks in forum Revit - API
    Replies: 4
    Last Post: 2009-01-27, 02:11 PM
  2. Publish DWF query
    By Dave F. in forum Revit - Platform
    Replies: 0
    Last Post: 2008-11-12, 10:33 AM
  3. Doing query through FDO
    By VBOYAJI in forum AutoCAD Map 3D - General
    Replies: 4
    Last Post: 2007-04-20, 09:38 AM
  4. map query's from GIS shapes
    By gisdude in forum AutoCAD Map 3D - General
    Replies: 3
    Last Post: 2006-03-31, 10:02 PM
  5. Massing query?
    By aliya14 in forum Revit Architecture - General
    Replies: 8
    Last Post: 2006-03-24, 03:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •