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

Insert Dynamic Block

8 REPLIES 8
Reply
Message 1 of 9
GegH1
706 Views, 8 Replies

Insert Dynamic Block

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 10 Pro 64bit, HP ZBook 17
8 REPLIES 8
Message 2 of 9
Alexander.Rivilis
in reply to: GegH1

Dynamic Block with Stretch Action

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

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 3 of 9
GegH1
in reply to: GegH1

Is this run from a form?

Creative Intentions
AutoCAD Certified Professional
Win 10 Pro 64bit, HP ZBook 17
Message 4 of 9
Alexander.Rivilis
in reply to: GegH1


@GegH1 wrote:

Is this run from a form?


And why not? You've already tried?

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 5 of 9
GegH1
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 10 Pro 64bit, HP ZBook 17
Message 6 of 9
DiningPhilosopher
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?

 

 

 

 

Message 7 of 9
GegH1
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 10 Pro 64bit, HP ZBook 17
Message 8 of 9
GegH1
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 10 Pro 64bit, HP ZBook 17
Message 9 of 9
Alexander.Rivilis
in reply to: GegH1

Please using search to find such ubiquitous errors: eLockViolation

 

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

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