.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Block overlay code has error:eInvalidInput

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
856 Views, 4 Replies

Block overlay code has error:eInvalidInput

Hi Guys,

 

I am writing code to create a new block based on an existing block. and place this new block on top of the existing one.

 

Here is my code

    Public Function FixtureConditionOverLay(objID as objectID) As Boolean
        Dim db As Database = acApp.DocumentManager.MdiActiveDocument.Database
        Dim trans As Transaction = acApp.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction
        Const strFDName As String = "FixDefects"
        Dim strDefectBlockName As String
        Try
            '--Get Block Ref 
            Dim objBRef As BlockReference = DirectCast(trans.GetObject(ObjID, OpenMode.ForRead), BlockReference)
            
            '--Check whether the blcok is exist
            strDefectBlockName = objBRef.name.tostring & "_" & strFDName 
            Dim objBT As BlockTable = db.BlockTableId.GetObject(OpenMode.ForWrite)
            If objBT.Has(strDefectBlockName) = False Then
                Dim objBTRHatch As BlockTableRecord = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)
                '--Create a block
                Dim objBTR As New BlockTableRecord
                objBTR.Name = strDefectBlockName
                Dim objIDs As New ObjectIdCollection
                objIDs.Add(objBRef.ObjectId)

                Dim objHatch As New Hatch
                objBTRHatch.AppendEntity(objHatch)
                trans.AddNewlyCreatedDBObject(objHatch, True)

                objHatch.SetDatabaseDefaults()
                objHatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI38")
                objHatch.PatternScale = 1
                objHatch.Color = Autodesk.AutoCAD.Colors.Color.FromRgb(20, 30, 30)
                objHatch.Associative = True
                objHatch.PatternAngle = 90
                objHatch.Annotative = AnnotativeStates.True
                objHatch.AppendLoop(HatchLoopTypes.Outermost, objIDs)   'error here eInvalidInput
                objHatch.EvaluateHatch(True)
                objBTRHatch.AppendEntity(objHatch)
                trans.AddNewlyCreatedDBObject(objBTR, True)
            End If

            'Insert the Block
            Dim myBTR As BlockTableRecord = objBT(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)

            Dim objNewBlock As BlockReference = New DatabaseServices.BlockReference(objBRef.Position, objBT(strDefectBlockName))
            ' myBlockRef.ScaleFactors = New Geometry.Scale3d(XScale, YScale, ZScale)
            objNewBlock.Rotation = objBRef.Rotation
            objNewBlock.Layer = STR_LAYER_FIXTUREDEFECT
            myBTR.AppendEntity(objNewBlock)
            trans.AddNewlyCreatedDBObject(objNewBlock, True)
            trans.Commit()
        Catch ex As Exception
            Debug.Assert(False)
            Debug.Print(ex.Message)
            trans.Abort()
        End Try
    End Function

 

But got problem here

objHatch.AppendLoop(HatchLoopTypes.Outermost, objIDs)   'error here eInvalidInput

 

can anybody help me?

 

Thanks very much

4 REPLIES 4
Message 2 of 5
chiefbraincloud
in reply to: Anonymous

You need to do the ObjBTRHatch.AppendEntity (and preferably the AddNewlyCreatedDBObject) before calling AppendLoop.

 

Dave O.                                                                  Sig-Logos32.png
Message 3 of 5
Anonymous
in reply to: chiefbraincloud

Thanks for reply.

 

I have done those, you can see from the code. I still got error

 

Any one can help me?

Message 4 of 5
chiefbraincloud
in reply to: Anonymous

Well, I see two of them in the code now, I didn't see the first one before.  So that's a problem.  You can only call those two once for each object.  I think I see what the problem is though.  It appears to me that your ObjectIDCollection only contains the ObjectID of the BlockReference.  I'm not sure if it will accept a block reference as a valid boundary object, so try exploding the blockreference and passing the objectids of the contents to the AppendLoop method.

Dave O.                                                                  Sig-Logos32.png
Message 5 of 5
Anonymous
in reply to: chiefbraincloud

Thanks for your reply.

 

I have tried to Explode the original object. And still the same problem on the same line.

Here is my new code

    Public Function FixtureConditionOverLay() As Boolean
        Dim db As Database = acApp.DocumentManager.MdiActiveDocument.Database
        Dim trans As Transaction = acApp.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction
        Const strFDName As String = "FixDefects"
        Dim strDefectBlockName As String
        Try
            '--Get Block Ref 
            Dim objBRef As BlockReference = DirectCast(trans.GetObject(MyBase.ObjectID, OpenMode.ForRead), BlockReference)
            '  Using lock As DocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument
            Dim tv() As TypedValue = objBRef.XData.AsArray
            m_enumFixtureDefect = tv(INDEX_XDATA_FIXTURE_CONDITION_STATUS).Value.ToString
            '--Check whether the blcok is exist
            strDefectBlockName = m_strBlockName & strFDName & m_enumFixtureDefect
            Dim objBT As BlockTable = db.BlockTableId.GetObject(OpenMode.ForWrite)

            If objBT.Has(strDefectBlockName) = False Then
                Dim objBTRHatch As BlockTableRecord = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)
                '--Create a block
                Dim objBTR As New BlockTableRecord
                objBTR.Name = strDefectBlockName
                Dim objIDs As New ObjectIdCollection

                '--Yaqi Test
                Dim objDBs As New DBObjectCollection
                objBRef.Explode(objDBs)
                For Each objDB As DBObject In objDBs
                    objBTRHatch.AppendEntity(objDB)
                    trans.AddNewlyCreatedDBObject(objDB, True)
                    objIDs.Add(objDB.ObjectId)
                Next


                Dim objHatch As New Hatch
                objBTRHatch.AppendEntity(objHatch)
                trans.AddNewlyCreatedDBObject(objHatch, True)

                objHatch.SetDatabaseDefaults()
                objHatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI38")
                objHatch.PatternScale = 1
                objHatch.Color = Autodesk.AutoCAD.Colors.Color.FromRgb(20, 30, 30)
                objHatch.Associative = True
                objHatch.PatternAngle = 90
                objHatch.Annotative = AnnotativeStates.True

                objHatch.AppendLoop(HatchLoopTypes.Outermost, objIDs)
                objHatch.EvaluateHatch(True)
                objBTRHatch.AppendEntity(objHatch)
                trans.AddNewlyCreatedDBObject(objBTR, True)
            End If


            'Insert the Block
            Dim myBTR As BlockTableRecord = objBT(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)

            Dim objNewBlock As BlockReference = New DatabaseServices.BlockReference(objBRef.Position, objBT(strDefectBlockName))
            ' myBlockRef.ScaleFactors = New Geometry.Scale3d(XScale, YScale, ZScale)
            objNewBlock.Rotation = objBRef.Rotation
            objNewBlock.Layer = STR_LAYER_FIXTUREDEFECT
            myBTR.AppendEntity(objNewBlock)
            trans.AddNewlyCreatedDBObject(objNewBlock, True)
            trans.Commit()
            '    End Using

        Catch ex As Exception
            trans.Abort()
        Catch ex As System.Exception
            Debug.Assert(False)
            Debug.Print(ex.Message)
            trans.Abort()
        End Try
    End Function

 

Thanks again

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost