Author Topic: pass command an argument  (Read 5796 times)

0 Members and 1 Guest are viewing this topic.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4076
pass command an argument
« on: April 28, 2008, 01:44:43 PM »
Can this be done?  I went thru the CommandMethod s and couldn't find one that seemed to take arguments (plural).
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: pass command an argument
« Reply #1 on: April 28, 2008, 01:58:08 PM »
What context of argument passing are you looking at? command line arguments? function arguments?
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Glenn R

  • Guest
Re: pass command an argument
« Reply #2 on: April 28, 2008, 01:58:20 PM »
Can this be done?

Not as far as I'm aware, as it's a COMMAND.

tjr

  • Guest
Re: pass command an argument
« Reply #3 on: April 28, 2008, 02:18:59 PM »
I believe you are looking for the LispFunction attribute instead of CommandMethod.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4076
Re: pass command an argument
« Reply #4 on: April 28, 2008, 02:23:59 PM »
I kinda thought I couldn't do it since I couldn't not find a method which would work.  I guess I know just enough LISP that I was thinking about the ability to call a function and pass arguments from the command line.

I guess i need to go back to the drawing board so to speak and figure out what I should do next.  In a nutshell, Im looking for the EASIEST way to maintain my stupid CUI file.  My thinking was if I had a function that I could pass a block name and layer to, the function would never have to be updated if I created a new block.  In the CUI, just call function and pas the 2 arguments needed.  YES, I know I can do this through LISP, I'm trying not to.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

tjr

  • Guest
Re: pass command an argument
« Reply #5 on: April 28, 2008, 02:30:59 PM »
I kinda thought I couldn't do it since I couldn't not find a method which would work.  I guess I know just enough LISP that I was thinking about the ability to call a function and pass arguments from the command line.

I guess i need to go back to the drawing board so to speak and figure out what I should do next.  In a nutshell, Im looking for the EASIEST way to maintain my stupid CUI file.  My thinking was if I had a function that I could pass a block name and layer to, the function would never have to be updated if I created a new block.  In the CUI, just call function and pas the 2 arguments needed.  YES, I know I can do this through LISP, I'm trying not to.

I'm uncertain as to what your problem really is as you can't pass any arguments to a function on the command line unless you do it via lisp, in a single line that is. If you create a LispFunction you can call it from the command line like (myfunc "myblock" "mylayer").

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: pass command an argument
« Reply #6 on: April 28, 2008, 02:36:00 PM »
If that is what you are doing, then see this and this for help in creating a command line version that will accept arguments in lisp.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4076
Re: pass command an argument
« Reply #7 on: April 28, 2008, 02:37:15 PM »
My problem is there are not enough hours in the day.  HAHA

I know just enough of so very little, I think I should be able to do things that are not possible.  I will look into the LispFunction to see if that might help me.  I guess my BIG question is how does everybody else use the CUI file for inserting blocks?  I might have to use lisp, which is fine.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: pass command an argument
« Reply #8 on: April 28, 2008, 02:40:39 PM »
You don't have to use lisp ..

define the function in .NET using LispFunction as indicated in the second URL in my previous post OR use CommandMethod and build the function as indicated in the first URL in my previous post ...

If you use LispFunction the call would be: (myfunction arg arg)
If you use CommandMethod the call would be (command "MyFunction" arg arg)
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

tjr

  • Guest
Re: pass command an argument
« Reply #9 on: April 28, 2008, 02:44:09 PM »
Or couldn't you just use good ol' macros in your CUI?

Code: [Select]
^C^C-INSERT ITEM_BALL S 4 \0

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4076
Re: pass command an argument
« Reply #10 on: April 28, 2008, 03:11:08 PM »
Or couldn't you just use good ol' macros in your CUI?
yes, which is where I'm kinda going, but I want to put more into the macro W/O it getting to long.  The basics of what Im after are
  • get current layer
  • insert block on correct layer
  • Set dynamic block visibily property
  • set layer back where it was when I started

I have a few different ways I could do this thru lisp or even VBA.  The idea was to avoid having to create a bucnh of 3 line VBA subs to call the main function into which I pass the required info.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: pass command an argument
« Reply #11 on: April 28, 2008, 03:20:58 PM »
No need to change the layer current, just change the object so it's on the correct layer.  I have a way to insert a block in .Net if you want to see it.  Right now its a sub, and asks for certain things, but that can be changed pretty easily.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4076
Re: pass command an argument
« Reply #12 on: April 28, 2008, 03:42:05 PM »
TW, i would like to see it.  My question is you say it asks for certain things, meaning the user needs to know the answer.  what if you wanted to somehow get around asking the user?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4076
Re: pass command an argument
« Reply #13 on: April 28, 2008, 03:43:14 PM »
Here is an example of my dyn block that has 4 states.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: pass command an argument
« Reply #14 on: April 28, 2008, 03:48:07 PM »
I have a VBA macro that forces a block to a specific layer, based upon user input. If you want to force only certain blocks to a certain layer, then all you need to do is turn off the auto-notify and manually mark the blocks and filters in the registry. It will only force those blocks.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

T.Willey

  • Needs a day job
  • Posts: 5251
Re: pass command an argument
« Reply #15 on: April 28, 2008, 04:16:33 PM »
Here you go.  What you need to supply right now is the Database you want the block inserted into, the Layout Name the block will be inserted into, the Block Name to insert, and the Point to insert.  I have a meeting at 1:30, so won't be able to check back for a while in case you have questions, but I will answer them if they are not answered when I check.  It will return the ObjectId of the inserted block if successful, it not it will return a Null ObjectId.

Code: [Select]
public static ObjectId InsertBlock ( Database db, string loName, string blkName, Point3d insPt ) {
        ObjectId RtnObjId = ObjectId.Null;
        using ( Transaction Trans = db.TransactionManager.StartTransaction( ) ) {
        DBDictionary LoDict = Trans.GetObject( db.LayoutDictionaryId, OpenMode.ForRead ) as DBDictionary;
        foreach ( DictionaryEntry de in LoDict ) {
        if ( string.Compare( ( string )de.Key, loName, true ).Equals( 0 ) ) {
        Layout Lo = Trans.GetObject( ( ObjectId )de.Value, OpenMode.ForWrite ) as Layout;
        BlockTable BlkTbl = Trans.GetObject( db.BlockTableId, OpenMode.ForRead ) as BlockTable;
        BlockTableRecord LoRec = Trans.GetObject( Lo.BlockTableRecordId, OpenMode.ForRead ) as BlockTableRecord;
        ObjectId BlkTblRecId = GetNonErasedTableRecordId( BlkTbl.Id, blkName );
        if ( BlkTblRecId.IsNull ) {
        string BlkPath = HostApplicationServices.Current.FindFile( blkName + ".dwg", db, FindFileHint.Default );
        if ( string.IsNullOrEmpty( BlkPath ) )
        return RtnObjId;
        BlkTbl.UpgradeOpen( );
        using ( Database tempDb = new Database( false, true ) ) {
        tempDb.ReadDwgFile( BlkPath, FileShare.Read, true, null );
        db.Insert( blkName, tempDb, false );
        }
        BlkTblRecId = GetNonErasedTableRecordId( BlkTbl.Id, blkName );
        }
        LoRec.UpgradeOpen( );
        BlockReference BlkRef = new BlockReference( insPt, BlkTblRecId );
        LoRec.AppendEntity( BlkRef );
        Trans.AddNewlyCreatedDBObject( BlkRef, true );
        BlockTableRecord BlkTblRec = Trans.GetObject( BlkTblRecId, OpenMode.ForRead ) as BlockTableRecord;
        if ( BlkTblRec.HasAttributeDefinitions ) {
        foreach ( ObjectId objId in BlkTblRec ) {
        AttributeDefinition AttDef = Trans.GetObject( objId, OpenMode.ForRead ) as AttributeDefinition;
        if ( AttDef != null ) {
        AttributeReference AttRef = new AttributeReference( );
        AttRef.SetAttributeFromBlock( AttDef, BlkRef.BlockTransform );
        BlkRef.AttributeCollection.AppendAttribute( AttRef );
        Trans.AddNewlyCreatedDBObject( AttRef, true );
        }
        }
        }
        Trans.Commit( );
        }
        }
        }
        return RtnObjId;
        }
It uses the sub by Tony T. also.

Code: [Select]
public static ObjectId GetNonErasedTableRecordId( ObjectId TableId, string Name )
        // Posted by Tony Tanzillo 01Sept2006
{
   ObjectId id = ObjectId.Null;
   using( Transaction tr = TableId.Database.TransactionManager.StartTransaction() )
   {
      SymbolTable table = (SymbolTable) tr.GetObject( TableId, OpenMode.ForRead );
      if( table.Has( Name ) )
      {
         id = table[Name];
         if( !id.IsErased )
            return id;
         foreach( ObjectId recId in table )
         {
            if( ! recId.IsErased )
            {
               SymbolTableRecord rec = (SymbolTableRecord) tr.GetObject( recId, OpenMode.ForRead );
               if( string.Compare( rec.Name, Name, true ) == 0 )
                  return recId;
            }
         }
      }
   }
   return id;
}
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Glenn R

  • Guest
Re: pass command an argument
« Reply #16 on: April 29, 2008, 04:44:29 AM »
Duh,

Can't you specify the layer in the properties for the tool on the palette directly? From memory you can set the layer and it will create it if necessary and place the block on that layer...at least you could last time I played with palettes.

Cheers,

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4076
Re: pass command an argument
« Reply #17 on: April 29, 2008, 10:07:59 AM »
Glenn, at this point we are not using palettes.  You are correct though, you can specify the layer in the props of the pallette.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)