TheSwamp

Code Red => .NET => Topic started by: David Hall on April 28, 2008, 01:44:43 PM

Title: pass command an argument
Post by: David Hall 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).
Title: Re: pass command an argument
Post by: Keith™ on April 28, 2008, 01:58:08 PM
What context of argument passing are you looking at? command line arguments? function arguments?
Title: Re: pass command an argument
Post by: Glenn R on April 28, 2008, 01:58:20 PM
Can this be done?

Not as far as I'm aware, as it's a COMMAND.
Title: Re: pass command an argument
Post by: tjr on April 28, 2008, 02:18:59 PM
I believe you are looking for the LispFunction attribute instead of CommandMethod.
Title: Re: pass command an argument
Post by: David Hall 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.
Title: Re: pass command an argument
Post by: tjr 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").
Title: Re: pass command an argument
Post by: Keith™ on April 28, 2008, 02:36:00 PM
If that is what you are doing, then see this (http://through-the-interface.typepad.com/through_the_interface/2006/09/passing_argumen.html) and this (http://through-the-interface.typepad.com/through_the_interface/2006/07/breathe_fresh_l.html) for help in creating a command line version that will accept arguments in lisp.
Title: Re: pass command an argument
Post by: David Hall 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.
Title: Re: pass command an argument
Post by: Keith™ 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)
Title: Re: pass command an argument
Post by: tjr 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
Title: Re: pass command an argument
Post by: David Hall 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
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.
Title: Re: pass command an argument
Post by: T.Willey 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.
Title: Re: pass command an argument
Post by: David Hall 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?
Title: Re: pass command an argument
Post by: David Hall on April 28, 2008, 03:43:14 PM
Here is an example of my dyn block that has 4 states.
Title: Re: pass command an argument
Post by: Keith™ 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.
Title: Re: pass command an argument
Post by: T.Willey 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;
}
Title: Re: pass command an argument
Post by: Glenn R 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,
Title: Re: pass command an argument
Post by: David Hall 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.