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.
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
@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
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."
yeah¡¡¡¡¡¡¡¡
thanks Kent1Cooper the first option work perfect¡¡¡¡¡
BlackboxCAD thanks for you answer, I study the code,probaly need it in a future.
"How we think determines what we do, and what we do determines what we get."