Author Topic: Help with Block Jigs Canceling Rotation = 0 Angle and Others....  (Read 3121 times)

0 Members and 1 Guest are viewing this topic.

deathman20

  • Guest
Help with Block Jigs Canceling Rotation = 0 Angle and Others....
« on: February 16, 2011, 01:01:45 PM »
Alright, after weeks of progress, finally think this is the route im taking with my Ribbon Bar Buttons to Insert Drawings.  Some background of what im doing is back in this post http://www.theswamp.org/index.php?topic=36783.0

So thanks to this helpful post http://forums.autodesk.com/t5/NET/Block-Insert-Jig-Byblock-Color/m-p/1855640#M5762 I was able to move forward with my project.  Im using the code as is from this link converted to VB .net and added into my Ribbon Bar

Lets me select an insertion point, and lets me rotate a block and its accepted by the ribbon bar button commands.  Some ones out there just don't like even acting as a command function with the ribbon bar buttons.

Very close to the insert command, but is there a way to...

A) Ability either insert the item as is, selecting a point as is and drops on the drawing with zero rotation?
B) Ability to hit "B" to select a new base point to move the block by
C) Ability to hit "R" to rotate the block
D) Ability to hit "M" to mirror the block (nifty option to have IMO)
E) Ability when the block is dropped on the drawing to automatically put it on "X" layer?

Not sure where to start to add these or if it can be done to the current code.


With canceling the command I know I've seen that you can supposedly use  "UserInputControls.NullResponseAccepted" in the code to make it cancel the selected item but its not working that way for me.  Its actually taking it as a point for rotation.

Located in the InsertBlockJig file

Code: [Select]
       Else
                    If vJigPromptCounter = 1 Then
                        ' JigPromptAngleOptions
                        Dim jigOpts As New JigPromptAngleOptions()
                        jigOpts.BasePoint = Me.BlockReference.Position
                        jigOpts.DefaultValue = 0
                        jigOpts.Message = "Get angle: "
                        jigOpts.UseBasePoint = True
  ---->                 jigOpts.UserInputControls = UserInputControls.Accept3dCoordinates & UserInputControls.NullResponseAccepted
                      
                        Dim res As PromptDoubleResult = prompts.AcquireAngle(jigOpts)

                        Dim curAngle As Double = res.Value
                        If Me.BlockReference.Rotation <> curAngle Then
                            blockRotation = curAngle
                        Else
                            Return SamplerStatus.NoChange
                        End If

                        If res.Status = PromptStatus.Cancel Then
                            Return SamplerStatus.Cancel
                        Else
                            Return SamplerStatus.OK
                        End If
                    Else
                        ' Just in case...
                        Return SamplerStatus.NoChange
                    End If
                End If

Thanks in advance!

PS. Sorry I didn't include the block files I was testing with it would get rather large.
« Last Edit: February 18, 2011, 04:46:48 PM by deathman20 »

deathman20

  • Guest
Re: Help with Block Jigs
« Reply #1 on: February 18, 2011, 03:19:22 PM »
Well got a function of it to work, did manage to get it to cancel.  If say I selected the wrong block, but for rotation since its a second option, trying to get it to just select a default option if canceled like 0.

Code: [Select]
            Protected Overrides Function Sampler(ByVal prompts As JigPrompts) As SamplerStatus
                If vJigPromptCounter = 0 Then
                    ' Maybe let the scale (and/or rotation) be changed with a option on the command-line
                    Me.BlockReference.ScaleFactors = New Scale3d(vScaleValue, vScaleValue, vScaleValue)
                    ' And eval rotation here...
                    If vRotationAngleUse Then
                        Me.BlockReference.Rotation = vRotationAngleValue
                    End If
                    ' Maybe still check the counter no (1) if the rotation was  set...

                    Dim jigOpts As New JigPromptPointOptions()
                    jigOpts.UserInputControls = UserInputControls.NoZeroResponseAccepted &
                        UserInputControls.NullResponseAccepted &
                        UserInputControls.Accept3dCoordinates

                    jigOpts.Message = vbLf & "Insertion point: "
                    Dim res As PromptPointResult = prompts.AcquirePoint(jigOpts)
                    'Point3d BlkRefPoint = BlockReference.Position;
                    Dim curPoint As Point3d = res.Value
                    If position.DistanceTo(curPoint) > 0.0001 Then
                        ' 1.0e-4 make it 10 units (depending on drawing...)
                        ' if (this.BlockReference.Position != curPoint)  // 1.0e-4 make it 10 units (depending on drawing...)
                        position = curPoint
                    Else
                        Return SamplerStatus.NoChange
                    End If

                    If res.Status = PromptStatus.Cancel Then
                        Return SamplerStatus.Cancel
                    Else
                        Return SamplerStatus.OK
                    End If
                Else
                    If vJigPromptCounter = 1 Then
                        ' Activate Rotate Jig...Just check if there already was a rotation...??
                        ' JigPromptAngleOptions
                        Dim jigOpts As New JigPromptAngleOptions()
                        jigOpts.BasePoint = Me.BlockReference.Position
                        jigOpts.DefaultValue = 0
                        jigOpts.Message = "Get angle: "
                        jigOpts.UseBasePoint = True
                        jigOpts.UserInputControls = UserInputControls.NoZeroResponseAccepted &
                            UserInputControls.NullResponseAccepted &
                            UserInputControls.Accept3dCoordinates

                        Dim res As PromptDoubleResult = prompts.AcquireAngle(jigOpts)

                        Dim curAngle As Double = res.Value
                        If Me.BlockReference.Rotation <> curAngle Then
                            blockRotation = curAngle
                        Else
                            Return SamplerStatus.NoChange
                        End If

                        If res.Status = PromptStatus.Cancel Then
                            Return SamplerStatus.Cancel
                        Else
                            Return SamplerStatus.OK
                        End If
                    Else
                        ' Just in case...
                        Return SamplerStatus.NoChange
                    End If
                End If

            End Function

deathman20

  • Guest
Re: Help with Block Jigs
« Reply #2 on: February 18, 2011, 04:27:07 PM »
Maybe the function im looking for is in this....  Though I've tried everything that I know, which isn't much, to cancel or default my rotation to 0 when the function is canceled.

Code: [Select]
       Public Sub StartInsert(ByVal JigBlockName As [String])

            Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
            Dim db As Database = HostApplicationServices.WorkingDatabase
            ' Application.DocumentManager.MdiActiveDocument.Database;
            Dim Normal As Vector3d = db.Ucsxdir.CrossProduct(db.Ucsydir)

            ' Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            ' PromptStringOptions opts = new PromptStringOptions("\nBlock name: ");
            ' opts.AllowSpaces = true;
            ' using( DocumentLock docLock = ed.Document.LockDocument() ) // Maybe Move this at first..??
            ' {
            Dim res As PromptResult
            ' = ed.GetString(opts);
            If JigBlockName <> String.Empty Then
                Dim block As ObjectId = GetBlockId(db, JigBlockName)
                If block.IsNull Then
                    ed.WriteMessage(vbLf & "Block {0} not found.", JigBlockName)
                    Return
                End If

                Dim jig As New InsertJig(block, Point3d.Origin, Normal.GetNormal())

                If vRotationUse = True Then
                    jig.RotationAngleUse = True
                    jig.RotationAngleValue = vRotationVal
                Else
                    jig.RotationAngleUse = False
                End If

                jig.ScaleValue = vScaleVal
                jig.JigPromptCounter = 0
                ' Start with insertpoint
                Using docLock As DocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument()
                    res = ed.Drag(jig)
                    ' First Jig option..[Insertpoint]
                    ' Should it accept a rightclick as the 0-point of the drawing?
                    ' or does that cancel the operation...?
                    If res.Status = PromptStatus.OK Then
                        ' Here also the Rotation-Jig should Start...
                        ' if Rotation was fixed this should have been set at first...
                        ' Should Accept rightclick as 0-rotation
                        ' Ready...end the Jig
                        If vRotationUse = True Then
                        Else
                            ' Start a new Jig for the rotation..
                            jig.JigPromptCounter = 1
                            res = ed.Drag(jig)
                        End If

                        ' if jig.RotationAngleUse = false then do it...
                        ' jig.RotationAngleValue = 1; // Or skip this al together if it's a given rotation...
                        ' No checking to be done by Jig(ger)..??

                        Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = db.TransactionManager


                        If res.Status = PromptStatus.OK Then
                            ' Second check needed if there was a rotation Jig..
                            Using tr As Transaction = tm.StartTransaction()
                                Dim bt As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead, False), BlockTable)
                                ' Do Check in what space You are!!!
                                ' It could be a Layout...
                                Dim btr As BlockTableRecord = DirectCast(tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite, False), BlockTableRecord)
                                btr.AppendEntity(jig.BlockReference)
                                tr.AddNewlyCreatedDBObject(jig.BlockReference, True)
                                tr.Commit()
                            End Using
                        End If
                    End If
                End Using
            End If
            ' }
        End Sub

deathman20

  • Guest
Re: Help with Block Jigs Canceling Rotation = 0 Angle and Others....
« Reply #3 on: March 03, 2011, 10:03:55 AM »
Well got it to work, fixed my issue with sort of a round about way.  Since I was running out of time to really figure out the issue I just scrapped the ribbon bar code, and went at it one step at a time.

Ended up figuring out how to use the insert command properly with Tony's Commandline code & this snipit to make it run.  Works perfectly with the ribbon bar.

Code: [Select]
Imports Autodesk.AutoCAD.Runtime

<Assembly: CommandClass(GetType(Insert.Commands))>

Namespace Insert
    Public Class Commands

        <CommandMethod("InsertBlock")> _
        Public Sub InsertConveyor()

            Commandline.Command("_Insert", "C:\Temp\" & RibbonBar.BlockName & ".dwg", "S", "1")

        End Sub

    End Class
End Namespace

That code fixed my issue, and have the full functionality of inserting the block like I would normally within Autocad without dealing with any jigging code.  Huge improvement, and nearly missed a deadline I set to see if I could get it to work at this time.

Now to see if the blocks can automatically be inserted on certain layers.  Mirroring can wait.
« Last Edit: March 03, 2011, 10:19:23 AM by deathman20 »