Hi,
I've been trying tons of different solutions to solve this problem: insert a block that has an attribute which happens to be the last object id.
This is the best code I tried so far but without any succss.
(defun c:q1()
(command "_.PLINE")
(while (= (getvar "CMDNAMES") "PLINE")
(command pause)
)
(setq objname (entlast))
(setq oad (getvar "attdia"))
(setq orq (getvar "attreq"))
(setq oec (getvar "cmdecho"))
(setvar "attdia" 1)
(setvar "attreq" 0)
(setvar "CMDECHO" 0)
(setq xScale 1)
(setq yScale 1)
(setq rot 0)
(setq at1 "abc")
(setq pt (getpoint "\nSpecify Insertion Point: "))
(command "_.insert" "TROC_PRP" pt xScale yScale rot objname)
(setvar "attdia" oad)
(setvar "attreq" orq)
(setvar "cmdecho" 1)
)
Can you help me?
Kind regards.
Solved! Go to Solution.
Solved by pbejse. Go to Solution.
Solved by pbejse. Go to Solution.
Solved by pbejse. Go to Solution.
Solved by pbejse. Go to Solution.
(defun c:q1 (/ objname p blk) (vl-load-com) (if (and (progn (command "_.PLINE") (while (= (getvar "CMDNAMES") "PLINE") (command pause)) T ) (setq objname (vlax-ename->vla-object (entlast))) (setq p (getpoint "\nSpecify Insertion Point: "))) (progn (setq blk (vlax-invoke (vlax-get (vla-get-ActiveLayout (vla-get-activedocument (vlax-get-acad-object))) 'Block) 'InsertBlock p "TROC_PRP" 1 1 1 0) ) (vla-put-textstring (car (vlax-invoke blk 'GetAttributes)) (itoa (vla-get-ObjectID objname))) ) ) (princ) )
No issues with ATTREQ /ATTDIA
I tried that but unfortunately it just doesn't insert the block after prompting for the block insertion point.
This is a copy of the command prompt:
Command: q1
_.PLINE
Specify start point:
Current line-width is 0.300
Specify next point or [Arc/Halfwidth/Length/Undo/Width]:
Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:
Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:
Command:
Specify Insertion Point:
Command:
(defun c:q1() (command "_.PLINE") (while (= (getvar "CMDNAMES") "PLINE") (command pause) ) (setq objname (vlax-ename->vla-object (entlast))) (setq oad (getvar "attdia")) (setq orq (getvar "attreq")) (setq oec (getvar "cmdecho")) (setvar "attdia" 0) (setvar "attreq" 1) (setvar "CMDECHO" 0) (setq xScale 1) (setq yScale 1) (setq rot 0) (setq at1 "abc") (setq pt (getpoint "\nSpecify Insertion Point: ")) (command "_.insert" "TROC_PRP" pt xScale yScale rot (itoa (vla-get-ObjectID objname))) (setvar "attdia" oad) (setvar "attreq" orq) (setvar "cmdecho" 1) )
ATTIDA 0
ATTREQ 1
Not the otehr way around
After setting ATTDIA and ATTREQ I tried again and this was the response:
Command: pl1
_.PLINE
Specify start point:
Current line-width is 0.300
Specify next point or [Arc/Halfwidth/Length/Undo/Width]:
Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:
Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:
Command:
Specify Insertion Point: ; error: Invalid number of parameters
My block has 4 attributes, is this relevant? I just want to enter the info for the first one (i.e. the polyline id).
@aabfm wrote:After setting ATTDIA and ATTREQ I tried again and this was the response:
My block has 4 attributes, is this relevant? I just want to enter the info for the first one (i.e. the polyline id).
Yes its relevant.
On your code
(command "_.insert" "TROC_PRP" pt xScale yScale rot
(itoa (vla-get-ObjectID objname)) "" "" "");<---- three carraige return
The first code I posted should bb able to take care of that
(car (vlax-invoke blk 'GetAttributes));<--- only the first one
If it still doesnt work post an example of the block here
I replaced my code acording to your suggestion, it inserts the block, no errors, but there's no info in any of the 4 attributes...
(command "_.insert" "TROC_PRP" pt xScale yScale rot (itoa (vla-get-ObjectID objname)) "" "" "")
Post an example of the block here... Ooops... Please help me...
@aabfm wrote:I replaced my code acording to your suggestion, it inserts the block, no errors, but there's no info in any of the 4 attributes...
(command "_.insert" "TROC_PRP" pt xScale yScale rot (itoa (vla-get-ObjectID objname)) "" "" "")
Post an example of the block here... Ooops... Please help me...
Quite understandable...
The reason why i opted for the VL apporach is to avoid issues with type of blocks:
Uniformly scaled and Not uniformly scaled//Annotative (Match Block insertion to layout)
Try inserting your block on the command prompt and see what properties you'll be prompted
command: -insert
Enter block name or [?] TROC_PRP"
Specify insertion point or [Basepoint/Scale/Rotate]:
Specify scale factor <1>:
Enter Y scale factor <use X scale factor>
Specify rotation angle <0>:
Enter attribute values
00 <00>:
value2
value3
value4
Depending on how your bllock is craeted it might or may not asked for Enter Y scale factor <use X scale factor>
If thats the case you need to remove yScale from your code
OK. Thanks.
Here it is:
Command: -insert
Enter block name or [?] <TROC_PRP>:
Units: Millimeters Conversion: 1.000
Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]:
Enter X scale factor, specify opposite corner, or [Corner/XYZ] <1>:
Enter Y scale factor <use X scale factor>:
Specify rotation angle <0.00>:
Enter attribute values
Cab:: 000111abc
Next line or <done>:
Lar:: 000111abc
Next line or <done>:
Lon:: 000111abc
Next line or <done>:
Tro:: 000111abc
Next line or <done>:
Command:
Looks fine to me:
Tell you waht just for fun
Repalce this
(command "_.insert" "TROC_PRP" pt xScale yScale rot
(itoa (vla-get-ObjectID objname)) "" "" "")
With :
(command "_.insert" "TROC_PRP" pt xScale yScale rot "1" "2" "3" "4")
and see where those numbers appears on your bllock
Make sure you have ATREQ 1 okay? You sure the irst code dint work on your block?
I think i'm havign a case of dejavu :smiley
Well...
Here is the result:
Command: attreq
Enter new value for ATTREQ <1>:
Command: q1
Specify Insertion Point: Unknown command "1". Press F1 for help.
Unknown command "2". Press F1 for help.
Unknown command "3". Press F1 for help.
Unknown command "4". Press F1 for help.
1
Command:
Tried again the first code and got the very same result...
@aabfm wrote:Well...
Here is the result:
Command: attreq
Enter new value for ATTREQ <1>:
Command: q1
Specify Insertion Point: Unknown command "1". Press F1 for help.
Unknown command "2". Press F1 for help.
Unknown command "3". Press F1 for help.
Unknown command "4". Press F1 for help.
1
Command:
Tried again the first code and got the very same result...
Do you happen to be using constant attributes?
Listen once and for all do this for me:
(defun c:testme nil
(vl-load-com)
(vlax-dump-object (vlax-ename->vla-object (Car (entsel)))))
(defun c:attme nil
(vl-load-com)
(foreach itm
(vlax-invoke (vlax-ename->vla-object (Car (entsel))) 'GetAttributes)
(print (list (vla-get-tagstring itm)(vla-get-textstring itm)))
)
(princ)
)
run these both on your block
RESULTS FOR TESTME
Command: testme1
Select object: ; IAcadBlockReference: AutoCAD Block Reference Interface
; Property values:
; Application (RO) = #<VLA-OBJECT IAcadApplication 00d591b4>
; Document (RO) = #<VLA-OBJECT IAcadDocument 223f48a0>
; EffectiveName (RO) = "TROC_PRP"
; Handle (RO) = "22B"
; HasAttributes (RO) = -1
; HasExtensionDictionary (RO) = 0
; Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 19273474>
; InsertionPoint = (-397560.0 -82539.0 0.0)
; InsUnits (RO) = "Millimeters"
; InsUnitsFactor (RO) = 1.0
; IsDynamicBlock (RO) = 0
; Layer = "0"
; Linetype = "ByLayer"
; LinetypeScale = 1.0
; Lineweight = -1
; Material = "ByLayer"
; Name = "TROC_PRP"
; Normal = (0.0 0.0 1.0)
; ObjectID (RO) = 1970845144
; ObjectName (RO) = "AcDbBlockReference"
; OwnerID (RO) = 1970855160
; PlotStyleName = "ByLayer"
; Rotation = 0.0
; TrueColor = #<VLA-OBJECT IAcadAcCmColor 224c0050>
; Visible = -1
; XEffectiveScaleFactor = 1.0
; XScaleFactor = 1.0
; YEffectiveScaleFactor = 1.0
; YScaleFactor = 1.0
; ZEffectiveScaleFactor = 1.0
; ZScaleFactor = 1.0
T
Command:
-x-x-x-x-x-x-
RESULTS FOR ATTME
Command: attme1
Select object:
("CAB" "")
("LAR" "")
("LON" "")
("TRO" "")
Command:
Well. i'm stumped Both code works for me , i even re-crated your block
One more go with this
Atrtreq 1
Qaflags 0
Attdia 0
AFlags 0
Are you sure its not a nested block?
When you insert a block via insert do you inidcate that its exploded?
Not constant, Not Dynamic/ None uniformly scaled
Trying to answer your questions:
- I've just gathered a few lines, 1 dtext;
- added 4 attributes (invisible checked);
- block;
- chose pick point;
- selected those items;
- scale uniformly checked;
- allow exploding checked;
- hit 'OK'.
Can figure through this description what I've done?
RESULTS WITH SYSTEM VARIABLES:
Command: attreq
Enter new value for ATTREQ <0>: 1
Command: qaflags
Enter new value for QAFLAGS <0>:
Command: attdia
Enter new value for ATTDIA <1>: 0
Command: aflags
Enter new value for AFLAGS <16>: 0
Command: q1
_.PLINE
Specify start point:
Current line-width is 0.300
Specify next point or [Arc/Halfwidth/Length/Undo/Width]:
Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:
Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:
Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:
Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:
Command:
Specify Insertion Point: Unknown command "1". Press F1 for help.
Unknown command "2". Press F1 for help.
Unknown command "3". Press F1 for help.
Unknown command "4". Press F1 for help.
1
Command: pl1
_.PLINE
Specify start point:
Current line-width is 0.300
Specify next point or [Arc/Halfwidth/Length/Undo/Width]:
Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:
Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:
Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:
Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:
Command:
Specify Insertion Point: ; error: Too many actual parameters
Didn't work...
However...
I open a new drawing copied the block, insert the LISP, and... IR WORKS!!!! But not on my inicial drawing...
Another piece of info:
I exploded a TROC_PRP block and checked the 4 attributes and they all have the multiple line field with 'yes'.
Does this matters?
Just found out another piece of info which might solve this out.
I'm using my client's UCS instead of World. I think this should be the problem because if I preform a general quick select for my block the counting turns out the correct one, i.e. the block actually is inserted but somewhere...
I've just used
(trans p 1 0)
instead of only
p
but since I have UCS rotated the block also shows rotated... 😞
Any ideas?...