TheSwamp
Code Red => .NET => Topic started by: deathman20 on January 21, 2011, 02:53:38 PM
-
Hello all,
Im new to coding and have created a ribbon bar now in .net though, been having a lovely time trying to work this one out but hitting road blocks. Below is my original thread I did on the Autodesk forums.
http://forums.autodesk.com/t5/NET/How-to-insert-a-drawing-via-Ribbon-Bar-Button/m-p/2887928
Private Sub addBCM1Chain(ByVal ribTab As RibbonTab)
'Create the panel source
Dim ribSourcePanel As RibbonPanelSource = New RibbonPanelSource()
ribSourcePanel.Title = "1 Chain"
'Create the panel
Dim ribPanel As New RibbonPanel()
ribPanel.Source = ribSourcePanel
ribTab.Panels.Add(ribPanel)
'Create a button
Dim ribBtn As Autodesk.Windows.RibbonButton = New RibbonButton()
ribBtn.Text = "Net load"
ribBtn.CommandParameter = ""
ribBtn.Orientation = Windows.Controls.Orientation.Vertical
ribBtn.Size = RibbonItemSize.Large
ribBtn.LargeImage = LoadImage("Block.png")
ribBtn.ShowImage = True
ribBtn.ShowText = True
ribBtn.CommandHandler = New AdskCommandHandler()
'Add the button
ribSourcePanel.Items.Add(ribBtn)
End Sub
The "ribBtn.CommandParameter = " is where im having issues with.
If I try this command after the = "-Insert Block"
It gets it going in the right direction. I can select a spot to drop the block on the drawing but then I have all the scale stuff to pass through.
If I try this command after the = "-Insert Block" & vbCrLf & "1" & vbCrLf & "1" & vbCrLf
Now it posts it but I don't get to select an insertion point. It picks some space where the last time your cursor clicked the model space.
Now if i try this command after the = "Insert " & "Block"
It brings up the block inserting window. Though not sure if this is how exactly the macro works or not that I have currently used inside autocad (which you can easily insert more blocks of the same type by right clicking). Though when the command is done it brings up the window, sits there at it (no text being put into the block line) and takes a few escapes and such to back out then runs the "Block" part of the command.
Trying to find a way to insert my macro code or something similar where I can click a button it gets the block, I can select where to put it in the drawing & have the option to rotate or select a new base point before it gets inserted into the drawing. Something similar if there you where using a tool pallet.
Thanks in advance.
-
Maybe found a way to do it properly using Tony's Commandline.
http://www.caddzone.com/CommandLine.vb
Though now I have an issue and don't know where to go from here.
'Commandline' is not a member of 'Autodesk.Windows.RibbonButton'
So how would I add the Commandline to function in part with the Autodesk.Windows.RibbonButton (etc since there are more commands out there like RibbonSplitButton)
-
Take a look at this class
http://au.autodesk.com/?nd=class&session_id=5163
-
Hi Jeff,
Yes the class is how I got this far already but im stuck with the ribBtn.CommandParameter right now.
The CommandParameter doesn't allow for a very nice way of trying to insert a block that I want to manipulate still, like selecting a point to drop it in the drawing and possible rotation. Scale I don't want to touch. Though using Tony's Commandline class that I've added to the project it works perfectly (somethings I still have to figure out) but it inserts it as I want it to. Now I just need to tie that to the ribbon button.
Though the Commandline class isn't a member of the Autodesk.Windows.RibbonButton functions. How would I go about adding the Class into that member group so I can use it as im intending.
Basically replacing this "ribBtn.CommandParameter" with "ribBtn.CommandLine"
-
You do have this class implemented?
Public Class AdskCommandHandler
Implements System.Windows.Input.ICommand
Public Function CanExecute(ByVal parameter As Object) _
As Boolean Implements System.Windows.Input.ICommand.CanExecute
Return True
End Function
Public Event CanExecuteChanged(ByVal sender As Object, ByVal e As System.EventArgs) _
Implements System.Windows.Input.ICommand.CanExecuteChanged
Public Sub Execute(ByVal parameter As Object) _
Implements System.Windows.Input.ICommand.Execute
Dim ribBtn As RibbonButton = TryCast(parameter, RibbonButton)
If ribBtn IsNot Nothing Then
acApp.DocumentManager.MdiActiveDocument.SendStringToExecute( _
ribBtn.CommandParameter, True, False, True)
End If
End Sub
End Class
This will send the string value stored in CommandParameter to the commandline
-
Here managed to clean up the code to show you.
Its just the inserting function that is bugging me. I can't get it to work as desired.
Jeff,
I'll check that out some more, I know mine is a little different from pulling it from a ribbon sample that was put out at AU and haven't totally cleaned it all up from it.
-
I would forget about the ribbon part and focus on creating a method with a CommandMethod attribute for inserting the block(for example named "insertconveyer")
then all you have to do set "insertconveyer" as the CommandParameter.
Start hitting buttons on the ribbon and watch the commandline it just sending commands to it
-
Yeah I did notice that the other day, though... well im new to this.
Im figuring minor things out as I go with trial and error so far but I haven't made anything from scratch.
I know I would need to make a new class is my guess to help with the command but I have no clue where to start and how to pull information from the button being pressed (to get the block name) and to run with it.
Any hints or suggestions?
I know im so close to getting this workable.
-
You could set the command parameter to "insertconveyer" to try to insert a block named 01M_Antriebsst_1000 is what I think you are trying to do
does this code make sense?
<CommandMethod("insertconveyer")> _
Public Sub insertconveyer()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Using trx As Transaction = db.TransactionManager.StartTransaction()
Dim bt As BlockTable = db.BlockTableId.GetObject(OpenMode.ForRead)
Dim btrMs As BlockTableRecord = bt(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForRead)
Dim btrObjId As ObjectId = bt("01M_Antriebsst_1000").GetObject(OpenMode.ForRead).ObjectId
Dim bref As New BlockReference(ed.GetPoint(vbLf & "Select Point").Value, btrObjId)
btrMs.UpgradeOpen()
btrMs.AppendEntity(bref)
trx.AddNewlyCreatedDBObject(bref, True)
trx.Commit()
ed.WriteMessage(vbLf & "Block Reference Inserted")
End Using
End Sub
-
Correct. Trying to get it to insert what I want to tell it. Could be 1 of over 2000+ names that is defined in the button, really the button text (ribBtn.Text = "01M_Antriebsst_0500")
Trying it right now but all im coming back with is Unknown Command "INSERTCONVEYOR"
Trying to play with it some more. Maybe I have it in the wrong location. Im putting it under the Public Class ConveyorRibbon.
-
This is quick way to go at it but maybe will give you a idea
commented out line for images because was causing it to fail
have a drawing with the 01M_Antriebsst_1000 & 01M_Antriebsst_500 block
netload then click buttons and pick insertion point
no jigging or error handling again just to give you a idea
-
Thanks Jeff,
Yes managed to get it to run just a few min ago with the previous code you posted. Must of missed something the first time I tried it.
Though im trying to figure out how to get it to not look in the block database. These are separate drawings located in a referenced directory on the harddrive. They will not be in the drawing unless its put in there. Otherwise drawings would be in the 300-350 meg range to start off, which wouldn't be cool.
Really do appreciate this greatly!
-
Do a search for WblockCloneObjects there are plenty of examples of grabbing blocks from external databases
-
Here is a start using a tool palette http://www.theswamp.org/index.php?topic=35280.0
Here is a nice one http://www.theswamp.org/index.php?topic=32990.0
-
Thanks Jeff
Had a nice set back for my work laptop. Decided to do the click of death this morning on boot up. So now Im waiting to get hopefully my projects of the drive.
-
Finally starting to get back to this. Messing around some more I did get a little further with it, though sadly its not what I was intending the outcome to be like with it.
I can get the blocks to inserted with a specific base point, and rotation. Though I don't see the block prior to insertion unlike the "Insert" command. I only see viability after I have my settings down. Even then right now I have to select a rotation, its not like I'd select it every time so there is a few disadvantages right now. As well selecting a new base point for insertion.
Used most of the code here, and had to re-adjust it to work with mine. Thanks to Jeff's code earlier to help me tweak it to make it work right.
What helped me along, converted the code from C# to .Net
http://forums.autodesk.com/t5/NET/Code-to-insert-a-dynamic-block-into-the-current-drawing/m-p/2849502#M21787
-
Though I don't see the block prior to insertion unlike the "Insert" command. I only see viability after I have my settings down. Even
Time to start learning jigs
-
Yup figured thats what it would be coming down to after looking a bit more last night.