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

Invalid Block Name

21 REPLIES 21
SOLVED
Reply
Message 1 of 22
Anonymous
3328 Views, 21 Replies

Invalid Block Name

Hey, getting an error with this lisp it keeps saying invalid block name. It exists and if I were to do insert manually it works just fine. So what gives? Here's the line of lisp.

(command "insert" "Block name" pt "" "")

21 REPLIES 21
Message 2 of 22
dbhunia
in reply to: Anonymous


@Anonymous wrote:

Hey, getting an error with this lisp it keeps saying invalid block name. It exists and if I were to do insert manually it works just fine. So what gives? Here's the line of lisp.

(command "_.insert" "Block name" pt "" "" "")


Try with above

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 3 of 22
Anonymous
in reply to: Anonymous

@Anonymous  Strange 🤔 , can you attach an example of your .dwg?

(command "_.Insert" "Block Name" pause 1 1 pause)
Message 4 of 22
Anonymous
in reply to: Anonymous

Its just a legend, I figured out the name issue. It doesnt need the quotes around it haha. However theres another issue, it wont insert. Obviously I dont have the syntax right but I dont know what I need to fix been monkeying around heres what I have so far. Getting a return of nil

 

(command "insert" blockName 4.3,6 "" "")

Message 5 of 22
Anonymous
in reply to: dbhunia

Tried that the file name cant be in quotes and the triple quotation set doesnt work either.

Message 6 of 22
_gile
in reply to: Anonymous

Hi,

 

try like this:

(command "_.insert" blockName "4.3,6" "" "" "")

or like this:

(command "_.insert" blockName '(4 3 6) "" "" "")


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 7 of 22
Anonymous
in reply to: _gile

Hmm, these dont work either. The first one gets an invalid selection error thrown, and the second one returns nil and then asks to select objects??

Message 8 of 22
dbhunia
in reply to: Anonymous


@Anonymous wrote:

Hmm, these dont work either. The first one gets an invalid selection error thrown, and the second one returns nil and then asks to select objects??


It never possible either it will work or "_.insert" will ask "Enter block name or [?] :"

 

And it natural whenever you pass any variable (value stored in it) in command that should never be within invited comma "" , otherwise it will be treated as string


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 9 of 22
Kent1Cooper
in reply to: dbhunia


@dbhunia wrote:

....

(command "_.insert" "Block name" pt "" "" "")


Try with above


 

That depends....  Is the Block defined for uniform scaling?  Whether or not it is will determine how many Enters to accept defaults for scale(s) and rotation are needed to complete the command.  If it's defined for uniform scaling, that last Enter will recall the previous command [not this Insert command, but the latest command from outside AutoLisp], which, depending on what kind of command that was, could explain the select-objects prompt mentioned in Message 7.

 

If you might use this with different Block names, using blockname as a variable holding the Block name as in some Messages here, some of which may be defined for uniform scaling but some not, you can get around the difference by explicitly calling for the Scale as an option, in which case it will ask for only one value, and apply it to all directions:

 

(command "_.insert" blockname "_scale" 1 pt "")

 

[that's if blockname is a variable -- if using the Block name itself, that would need double-quotes around it].

Kent Cooper, AIA
Message 10 of 22
dbhunia
in reply to: Kent1Cooper

You are absolutely right, every thing is relative.......

 

We need to ask him for sample of Drawing (with Block) & the LISP.......

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 11 of 22
Kent1Cooper
in reply to: _gile


@_gile wrote:
....
or like this:
(command "_.insert" blockName '(4 3 6) "" "" "")

 

[Given the source example, that should have a decimal point rather than a space between the 4 and the 3.  But it shouldn't make any difference to whether it functions, since Blocks can  be Inserted at locations with non-zero Z coordinates.  So if it still doesn't work, something else is going on, such as the uniform-scaling possibility, though I don't see that explaining all the difficulties described.]

Kent Cooper, AIA
Message 12 of 22
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

[in reply to @_gile's two suggestions in Message 6]

Hmm, these dont work either. The first one gets an invalid selection error thrown, and the second one returns nil and then asks to select objects??


 

Does the second one succeed in Inserting the Block, aside from the message?  If it's a Block defined for uniform scaling, what you describe is what I would expect.  The last "" in it would recall whatever outside-AutoLisp command was last used, presumably one requiring object selection, and the nil is what the (command) function always returns when finished.

 

As to the invalid selection message from the first one, since Insert doesn't involve selection, I wonder:  did you perhaps run the code when still in some other command?  If you ensure you're not  in a command, and run it again, do you get the same message?

Kent Cooper, AIA
Message 13 of 22
Anonymous
in reply to: Kent1Cooper

I dont think its defined for uniform scaling then. Heres the file

Message 14 of 22
Anonymous
in reply to: Kent1Cooper

Yeah it was entered during another command, retried it, still no results.

Message 15 of 22
_gile
in reply to: Anonymous

This works if the the block table already contains the "OB_K legend" block definition.

 

(setq blockname "OB_K legend")
(command "_.insert" blockname '(4.3 6) "" "" "")


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 16 of 22
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

..... Heres the file


So apparently it's Inserting an external drawing file, not a Block defined in the current drawing.  Then I don't think it can be limited to uniform scaling -- I'm not positive, but I think that can only be part of a Block definition inside a drawing.

 

Next question:  How  are you specifying what to Insert, whether directly or saved as a variable?  With just the name, and if so, is it located in a folder that AutoCAD knows to look in?  Or are you including a filepath, and are you sure you have it all correct?  And are you using forward  slashes or double  backslashes as separators in the file path?  [You can't use the typical filepath-separator single backslashes in AutoLisp strings, since they are used to cue special characters.]  Are you perhaps using (getfiled) to get it [which should ensure that it's formatted correctly]?

Kent Cooper, AIA
Message 17 of 22
Anonymous
in reply to: Kent1Cooper

I can make a list of everything I have tried. Otherwise right now I'm just passing it as a filepath, have exhausted everything I can think of with the formatting on that. Can you successfully insert the block?

Message 18 of 22
dbhunia
in reply to: Anonymous

check this.......

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 19 of 22
Sea-Haven
in reply to: Anonymous

My $0.05 I have always used  -Insert

Message 20 of 22
Kent1Cooper
in reply to: Sea-Haven


@Sea-Haven wrote:

My $0.05 I have always used  -Insert


Not necessary inside a (command) function, where the command-line version rather than the dialog-box version of commands is always used, unless you force the dialog box by preceding it with (initdia).

Kent Cooper, AIA

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

Post to forums  

Forma Design Contest


Autodesk Design & Make Report