.NET

Reply
Distinguished Contributor
GegH1
Posts: 119
Registered: ‎03-12-2004
Message 1 of 9 (287 Views)

Insert Dynamic Block

287 Views, 8 Replies
04-06-2013 03:21 AM

I am trying to insert a dynamic block and position and stretch the block, using the linear parameters, depending on values entered into a form.

 

Has anyone done anything similar. I managed to create a form that would draw a series of boxes. And i managed to create a routine that would insert a block and size it depending on fixed values but i can't link the 2 together.

 

I'm more than happy to share what i have so far if someone is willing to help

Creative Intentions
AutoCAD Certified Professional
Win 7 Pro 64bit, Dell Precision M6500
Moderator
Alexander.Rivilis
Posts: 1,406
Registered: ‎04-09-2008
Message 2 of 9 (276 Views)

Re: Insert Dynamic Block

04-06-2013 04:33 AM in reply to: GegH1

Dynamic Block with Stretch Action

How to access and modify a DynamicBlockReference property in ARX and .Net?


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Distinguished Contributor
GegH1
Posts: 119
Registered: ‎03-12-2004
Message 3 of 9 (268 Views)

Re: Insert Dynamic Block

04-06-2013 05:17 AM in reply to: GegH1

Is this run from a form?

Creative Intentions
AutoCAD Certified Professional
Win 7 Pro 64bit, Dell Precision M6500
Moderator
Alexander.Rivilis
Posts: 1,406
Registered: ‎04-09-2008
Message 4 of 9 (254 Views)

Re: Insert Dynamic Block

04-06-2013 08:22 AM in reply to: GegH1

GegH1 wrote:

Is this run from a form?


And why not? You've already tried?


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Distinguished Contributor
GegH1
Posts: 119
Registered: ‎03-12-2004
Message 5 of 9 (237 Views)

Re: Insert Dynamic Block

04-06-2013 05:45 PM in reply to: Alexander.Rivilis

I've got the code that manipulates the block,i can't however get it to work with a form, how does your code differ from that?

Creative Intentions
AutoCAD Certified Professional
Win 7 Pro 64bit, Dell Precision M6500
Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 6 of 9 (232 Views)

Re: Insert Dynamic Block

04-06-2013 07:19 PM in reply to: GegH1

GegH1 wrote:

I've got the code that manipulates the block,i can't however get it to work with a form, how does your code differ from that?


You're asking someone to tell you how their code differs from what?  Your code?  

 

Are you expecting an answer without seeing your code?

 

 

 

 

Distinguished Contributor
GegH1
Posts: 119
Registered: ‎03-12-2004
Message 7 of 9 (229 Views)

Re: Insert Dynamic Block

04-06-2013 07:47 PM in reply to: DiningPhilosopher

Here's the code i'm using which works with the attched drawing. The last bit with hard coded values manipulates the block, i need a form to put the numbers in

 

Imports

Autodesk.AutoCAD.Runtime

Imports

Autodesk.AutoCAD

Imports

Autodesk.AutoCAD.DatabaseServices

Imports

Autodesk.AutoCAD.EditorInput

Imports

Autodesk.AutoCAD.Geometry

Imports

Autodesk.AutoCAD.ApplicationServices

Imports

Autodesk.AutoCAD.ApplicationServices.Application

Imports

Autodesk.AutoCAD.LayerManager

Imports

Autodesk.AutoCAD.Windows

Imports

System.Math

Public

ClassCommands

    <

CommandMethod("DrawShed")> _

   

PublicSub DrawShed()

       

Dim recFrm AsNewShedForm()

       

Application.ShowModelessDialog(recFrm)

   

EndSub

End

Class

Public

ClassRectangle

   

PublicFunction InsertBlock(ByVal DatabaseIn AsDatabase, _

            

ByVal BTRToAddTo AsString, _

            

ByVal InsPt As Geometry.Point3d, _

            

ByVal BlockName AsString, _

            

ByVal XScale AsDouble, _

            

ByVal YScale AsDouble, _

            

ByVal ZScale AsDouble) As DatabaseServices.ObjectId

       

Using myTrans AsTransaction = DatabaseIn.TransactionManager.StartTransaction

           

Dim myBlockTable AsBlockTable = DatabaseIn.BlockTableId.GetObject(OpenMode.ForRead)

           

'If the suppplied Block Name is not

           

'in the specified Database, get out gracefully.

           

If myBlockTable.Has(BlockName) = FalseThen

               

ReturnNothing

           

EndIf

           

'If the specified BlockTableRecord does not exist,

           

'get out gracefully

           

If myBlockTable.Has(BTRToAddTo) = FalseThen

               

ReturnNothing

           

EndIf

           

Dim myBlockDef AsBlockTableRecord = _

                myBlockTable(BlockName).GetObject(

OpenMode.ForRead)

           

Dim myBlockTableRecord AsBlockTableRecord = _

myBlockTable(BTRToAddTo).GetObject(

OpenMode.ForWrite)

           

'Create a new BlockReference

           

Dim myBlockRef AsNewBlockReference(InsPt, myBlockDef.Id)

           

'Set the scale factors

            myBlockRef.ScaleFactors =

New Geometry.Scale3d(XScale, YScale, ZScale)

           

'Add the new BlockReference to the specified BlockTableRecord

            myBlockTableRecord.AppendEntity(myBlockRef)

           

'Add the BlockReference to the BlockTableRecord.

            myTrans.AddNewlyCreatedDBObject(myBlockRef,

True)

           

Dim myAttColl As DatabaseServices.AttributeCollection = _

                myBlockRef.AttributeCollection

           

'Find Attributes and add them to the AttributeCollection

           

'of the BlockReference

           

ForEach myEntID AsObjectIdIn myBlockDef

               

Dim myEnt AsEntity = myEntID.GetObject(OpenMode.ForRead)

               

IfTypeOf myEnt Is DatabaseServices.AttributeDefinitionThen

                   

Dim myAttDef As DatabaseServices.AttributeDefinition = myEnt

                   

Dim myAttRef AsNew DatabaseServices.AttributeReference

                    myAttRef.SetAttributeFromBlock(myAttDef, myBlockRef.BlockTransform)

                    myAttColl.AppendAttribute(myAttRef)

                    myTrans.AddNewlyCreatedDBObject(myAttRef,

True)

               

EndIf

           

Next

            myTrans.Commit()

           

Return myBlockRef.Id

       

EndUsing

   

EndFunction

   

Function SetParameter(ByVal BlockID AsObjectId, ByVal ParameterName AsString, _

           

ByVal Value AsDouble) AsBoolean

       

Using myTrans AsTransaction = BlockID.Database.TransactionManager.StartTransaction

           

Dim myBRef AsBlockReference = BlockID.GetObject(OpenMode.ForRead)

           

ForEach myDynamProp AsDynamicBlockReferencePropertyIn _

                    myBRef.DynamicBlockReferencePropertyCollection

               

If myDynamProp.PropertyName.Equals( _

                        ParameterName,

StringComparison.OrdinalIgnoreCase) = TrueThen

                    myDynamProp.Value = Value

                    myTrans.Commit()

                   

ReturnTrue

                   

Exit For

               

EndIf

           

Next

           

ReturnFalse

       

EndUsing

   

EndFunction

   

Private _length AsDouble

   

PublicProperty Length() AsDouble

       

Get

           

Return _length

       

EndGet

       

Set(ByVal value AsDouble)

            _length = value

       

EndSet

   

EndProperty

   

Private _width AsDouble

   

PublicProperty Width() AsDouble

       

Get

           

Return _width

       

EndGet

       

Set(ByVal value AsDouble)

            _width = value

       

EndSet

   

EndProperty

   

Private _height AsDouble

   

PublicProperty Height() AsDouble

       

Get

           

Return _height

       

EndGet

       

Set(ByVal value AsDouble)

            _height = value

       

EndSet

   

EndProperty

   

Private _slope AsDouble

   

PublicProperty slope() AsDouble

       

Get

           

Return _slope

       

EndGet

       

Set(ByVal value AsDouble)

            _slope = value

       

EndSet

   

EndProperty

   

SubNew(ByVal length AsDouble, ByVal width AsDouble, ByVal height AsDouble, ByVal slope AsDouble)

 

       

Me.Length = length

       

Me.Width = width

       

Me.Height = height

       

Me.slope = slope

   

EndSub

 

   

PublicSub InsertBlockSetPointParameter()

       

Dim doc AsDocument = Application.DocumentManager.MdiActiveDocument

       

Dim db AsDatabase = doc.Database

       

Dim radians AsDouble = slope * PI / 180

       

Dim RL AsDouble = Tan(radians) * (Width / 2)

       

Dim TP AsDouble = Height + RL

       

Dim myBlockID AsObjectId = InsertBlock(HostApplicationServices.WorkingDatabase, _

                                               

BlockTableRecord.ModelSpace, _

                                               

NewPoint3d(1, 1, 0), "Plan_Base", 1, 1, 1)

        SetParameter(myBlockID,

"P_Len", Length)

        SetParameter(myBlockID,

"P_Width", Width)

        SetParameter(myBlockID,

"Ridge_Height_LE", TP)

        SetParameter(myBlockID,

"Ridge_Height_RE", TP)

        SetParameter(myBlockID,

"Shed_Height_LE", Height)

        SetParameter(myBlockID,

"Shed_Height_RE", Height)

        SetParameter(myBlockID,

"Shed_Height_Front", Height)

        SetParameter(myBlockID,

"Ridge_Height_Front", TP)

        SetParameter(myBlockID,

"Shed_Height_Back", Height)

        SetParameter(myBlockID,

"Ridge_Height_Back", TP)

   

EndSub

End

Class

 

Creative Intentions
AutoCAD Certified Professional
Win 7 Pro 64bit, Dell Precision M6500
Distinguished Contributor
GegH1
Posts: 119
Registered: ‎03-12-2004
Message 8 of 9 (221 Views)

Re: Insert Dynamic Block

04-07-2013 01:08 AM in reply to: GegH1

It seems i am getting an eLockViolation

 

           

Dim myBlockTableRecord AsBlockTableRecord = _

                myBlockTable(BTRToAddTo).GetObject(

OpenMode.ForWrite)

 

Full Function

 

Public

ClassInsBlock

   

PublicFunction InsertBlock(ByVal DatabaseIn AsDatabase, _

        

ByVal BTRToAddTo AsString, _

        

ByVal InsPt As Geometry.Point3d, _

        

ByVal BlockName AsString, _

        

ByVal XScale AsDouble, _

        

ByVal YScale AsDouble, _

        

ByVal ZScale AsDouble) As DatabaseServices.ObjectId

       

Using myTrans AsTransaction = DatabaseIn.TransactionManager.StartTransaction

           

Dim myBlockTable AsBlockTable = DatabaseIn.BlockTableId.GetObject(OpenMode.ForRead)

           

'If the suppplied Block Name is not

           

'in the specified Database, get out gracefully.

           

If myBlockTable.Has(BlockName) = FalseThen

               

ReturnNothing

           

EndIf

           

'If the specified BlockTableRecord does not exist,

           

'get out gracefully

           

If myBlockTable.Has(BTRToAddTo) = FalseThen

               

ReturnNothing

           

EndIf

           

Dim myBlockDef AsBlockTableRecord = _

                myBlockTable(BlockName).GetObject(

OpenMode.ForRead)

           

Dim myBlockTableRecord AsBlockTableRecord = _

myBlockTable(BTRToAddTo).GetObject(

OpenMode.ForWrite)

           

'Create a new BlockReference

           

Dim myBlockRef AsNewBlockReference(InsPt, myBlockDef.Id)

           

'Set the scale factors

            myBlockRef.ScaleFactors =

New Geometry.Scale3d(XScale, YScale, ZScale)

           

'Add the new BlockReference to the specified BlockTableRecord

            myBlockTableRecord.AppendEntity(myBlockRef)

           

'Add the BlockReference to the BlockTableRecord.

            myTrans.AddNewlyCreatedDBObject(myBlockRef,

True)

           

Dim myAttColl As DatabaseServices.AttributeCollection = _

                myBlockRef.AttributeCollection

           

'Find Attributes and add them to the AttributeCollection

           

'of the BlockReference

           

ForEach myEntID AsObjectIdIn myBlockDef

               

Dim myEnt AsEntity = myEntID.GetObject(OpenMode.ForRead)

               

IfTypeOf myEnt Is DatabaseServices.AttributeDefinitionThen

                   

Dim myAttDef As DatabaseServices.AttributeDefinition = myEnt

                   

Dim myAttRef AsNew DatabaseServices.AttributeReference

                    myAttRef.SetAttributeFromBlock(myAttDef, myBlockRef.BlockTransform)

                    myAttColl.AppendAttribute(myAttRef)

                    myTrans.AddNewlyCreatedDBObject(myAttRef,

True)

               

EndIf

           

Next

            myTrans.Commit()

           

Return myBlockRef.Id

       

EndUsing

   

EndFunction

Creative Intentions
AutoCAD Certified Professional
Win 7 Pro 64bit, Dell Precision M6500
Moderator
Alexander.Rivilis
Posts: 1,406
Registered: ‎04-09-2008
Message 9 of 9 (214 Views)

Re: Insert Dynamic Block

04-07-2013 05:44 AM in reply to: GegH1

Please using search to find such ubiquitous errors: eLockViolation

 

 


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.