Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

insert point at list block and dinamic block

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
andresep82
902 Views, 4 Replies

insert point at list block and dinamic block

Hello,

 

this  is my  first post.I am learning autolips and i found  a problem that i can´t solved.

 

(vl-load-com)
(defun c:pmb ( / ss ent pt  )

(prompt "\nselec block : ")

(setq ss (ssget '((0 . "INSERT"))))


    (setq ent (ssname ss 0)),
    (setq pt (cdr (assoc 10 (entget ent))))
    
(command "point" pt)	

)

 wich this code you select one block and insert one point at insert point´s block.

 

which this other code yo select all block and insert all  point.... but in one block

 

    (vl-load-com)
    (defun c:pmb11 ( / sele cod  bloque  nbloque lista  pt  )

     (prompt "\nblock: ")
    (setq sele (ssget  ( List'(0 . "INSERT")))

      Cod 0

    )

cod (1+ cod)

   (repeat
	
    (sslength sele)

    (setq bloque (ssname sele cod))


   (setq pt (cdr (assoc 10 ( entget bloque)))) 
        (command "punto" pt)   


    );repeat

    )

 

how i can fix it?  point should insert one to one at block not together.

 

 

and.....for dinamic block?

 

can you hell me?

 

sorry for my  bad english.

 

 

 

 

4 REPLIES 4
Message 2 of 5
Kent1Cooper
in reply to: andresep82


@andresep82 wrote:
... this other code yo select all block and insert all  point.... but in one block

 

how i can fix it?  point should insert one to one at block not together.

  

and.....for dinamic block?

.... 


[I don't have a new-enough version for dynamic Blocks, but I wouldn't think that would matter.  It's just looking for the insertion points, which I don't think are different for dynamic Blocks than ordinary ones.]

 

You need the changing of the 'cod' variable to be inside the (repeat) function.  It appears that you're trying to increase it by one, though it's not in a (setq) function that would do that, but even if it were, it's only increased once, before the (repeat) function, and then the routine puts Points at the insertion of just one Block, because the 'cod' variable remains at the same value.

 

Try something like this [untested]:

 

(defun c:pmb11 (/ sele cod bloque pt)
  (prompt "\nblock: ")
  (setq

    sele (ssget '((0 . "INSERT")))
    cod 0
  ); end setq
  (repeat (sslength sele)
    (setq

      bloque (ssname sele cod)
      pt (cdr (assoc 10 (entget bloque)))

    ); end setq
    (command "punto" pt)  
    (setq cod (1+ cod))
  ); end repeat
); end defun

 

Or, you can do it without the 'cod' variable at all, if you like.  It can look at the first item in the selection every time, and remove that item from the selection after it has put a Point at its insertion, so that it sees the next item when it repeats:

 

(defun c:pmb11 (/ sele bloque pt)

  (prompt "\nblock: ")

  (setq sele (ssget '((0 . "INSERT"))))

  (repeat (sslength sele)

    (setq

      bloque (ssname sele 0)

      pt (cdr (assoc 10 (entget bloque)))

    ); end setq

    (command "punto" pt)

    (ssdel bloque sele)

  ); end repeat

); end defun

Kent Cooper, AIA
Message 3 of 5
BlackBox_
in reply to: Kent1Cooper

While there are a couple of pure AutoLISP adaptations already posted, I would caution against removing items from a data set actively being iterated... Tony recently commented to this affect as well... Therefor I would add a 1+ for the Repeat / While (not posted) version.

 

For completeness, here is a Visual LISP adaptation, perhaps a bit less efficient than the AutoLISP version due to defining the necessary Vla-Objects, but for one who already has multiple global variables, this is no longer an issue... Further, this adaptation allows for a single Undo point (rolling back all points added for each invocation), and also precludes the user from adding a point to an external reference (also DxfCode 0 / Insert).

 

Please take from this what you like:

 

(vl-load-com)

(defun c:FOO (/ *error* ss acDoc oBlocks oSpace)

  (defun *error* (msg)
    (if acDoc
      (vla-endundomark acDoc)
    )
    (cond ((not msg))                                                   ; Normal exit
          ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
          ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
    )
    (princ)
  )

  (if (setq ss (ssget '((0 . "INSERT"))))
    (progn
      (vla-startundomark
        (setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
      )
      (setq oBlocks (vla-get-blocks acDoc))
      (setq oSpace
             (apply
               (if (= 1 (getvar 'tilemode))
                 'vla-get-modelspace
                 'vla-get-paperspace
               )
               (list acDoc)
             )
      )
      (vlax-for x (setq ss (vla-get-activeselectionset acDoc))
        (if (= :vlax-false
               (vla-get-isxref
                 (vla-item oBlocks (vla-get-effectivename x))
               )
            )
          (vla-addpoint oSpace (vla-get-insertionpoint x))
        )
      )
      (vla-delete ss)
    )
    (prompt "\n** Nothing selected ** ")
  )
  (*error* nil)
)

 

Cheers



"How we think determines what we do, and what we do determines what we get."

Message 4 of 5
andresep82
in reply to: andresep82

 

yeah¡¡¡¡¡¡¡¡

 

 

thanks  Kent1Cooper the first option work perfect¡¡¡¡¡

 

 

BlackboxCAD thanks for you answer, I study the code,probaly need it in a future.

Message 5 of 5
BlackBox_
in reply to: andresep82

I agree that Kent's first offering is the best (and simplest) solution given the stated goal. :thumbsup:

You're welcome andresep82; I'm happy to help.

Cheers


"How we think determines what we do, and what we do determines what we get."

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost