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

.net form to change dynamic blocks

12 REPLIES 12
Reply
Message 1 of 13
inlinefg
1255 Views, 12 Replies

.net form to change dynamic blocks

Hi, I am new to .net customization but I would like to know if the following is possible.

 

I need to build a form web site that contains a series of drop down lists.

I have a lot of drawings that are basically section details, each one containing a dynamic block with 2-3 different visibility parameters.

 

My program should identify the drawings based on user selection and modify each dynamic block as required by the user data, then print each layout and produce a single multipage as a PDF.

 

This is the short version and I would like to know if it is possible in .net, and if anyone is willing to help.

 

Thank you.

Tags (2)
12 REPLIES 12
Message 2 of 13
hgasty1001
in reply to: inlinefg

Hi,

 

It's doable, but you should read the EULA of AutoCAD, I think that the EULA doesn't permit the use of AutoCAD in a server or as a server.

 

Gaston Nunez

Message 3 of 13
inlinefg
in reply to: hgasty1001

thank you gasty1001, can you help me identify the dynamic block visibility state and how to change this .net?

I will check into EULA

Message 4 of 13
hgasty1001
in reply to: inlinefg

Hi,

 

This code will insert a dynamic block with a visibility state (visState):

 

Public Sub InsertDynBlock(ByVal basePath As String, ByVal blkName As String, ByVal p As Point3d, ByVal sx As Double, ByVal sy As Double, ByVal theta As Double, ByVal blkLayer As String, ByVal attLayer As String, ByVal visState As String)
        Dim db As Database
        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
        Dim blkFile As String = basePath + "\\" + blkName + ".dwg"


        db = HostApplicationServices.WorkingDatabase()
        
        Using acTrans As Transaction = db.TransactionManager.StartTransaction()

            Dim bt As BlockTable = acTrans.GetObject(db.BlockTableId, OpenMode.ForRead)
            Dim btr As BlockTableRecord
            btr = acTrans.GetObject(bt.Item(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
            Dim id As ObjectId
            If bt.Has(blkName) Then
                Dim btrSrc As BlockTableRecord
                btrsrc=acTrans.GetObject(bt.Item(blkName), OpenMode.ForRead)
                id = btrSrc.Id
            Else
                Try
                    Dim dbDwg As New Database(False, True)
                    dbDwg.ReadDwgFile(blkFile, IO.FileShare.Read, True, "")
                    id = db.Insert(blkName, dbDwg, True)
                    dbDwg.Dispose()
                Catch ex As Exception
                    MsgBox(blkName + ":" + ex.Message)
                    Exit Sub
                End Try

            End If

            Dim blkRef As New BlockReference(p, id)
            Dim sc As New Scale3d(sx, sy, 1)
            blkRef.Layer = blkLayer
            blkRef.Rotation = theta
            blkRef.ScaleFactors = sc
            btr.AppendEntity(blkRef)
            acTrans.AddNewlyCreatedDBObject(blkRef, True)

            'Dim RefBTR As BlockTableRecord = acTrans.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead)
            Dim dPropsCollection As DynamicBlockReferencePropertyCollection

            dPropsCollection = blkRef.DynamicBlockReferencePropertyCollection

            For Each dprop As DynamicBlockReferenceProperty In dPropsCollection
                If dprop.PropertyName = "SomeVisState" Then
                    dprop.Value = visState
                End If
            Next
                       

            Try
                btr.UpdateAnonymousBlocks()
                blkRef.RecordGraphicsModified(True)
            Catch ex As Autodesk.AutoCAD.Runtime.Exception
                MsgBox("Updating RefBTR:blkName :" + ex.Message)
            End Try
            acTrans.Commit()

        End Using
    End Sub

 

Gaston Nunez

Message 5 of 13
inlinefg
in reply to: hgasty1001

Gasty, I am not sure I know how to use this code, but it is not working for me.

 

Let me give you more information.

 

This should be OK by EULA. I hope.

 

The solution should be an Autocad UserForm with drop down selections.

 

First selection should be "Series" I can have this list in an SQL table ex. 200, 300, 400 ...

Second selection is "Exterior Options" ex. 120,130,140 ... maybe there is a way to read and populate directly from the dwg, or i can just buld this list

Third selection is "Interior Options" ex. 005, 006 ... 

 

Say we chose 200, 120, 005

 

200 - Should open or edit The 200.dwg This file contains 3 dynamic blocks (UP, Down, Side) each one on a different paper space as a view port

         we don't want to change this drawing (add or insert geometry), only need to change the visibility state and print as PDF.

120 - Is one of The visibility states for all 3 blocks into drawing 200.dwg

005 - Is another visibility state, again for all 3 blocks from drawing 200.dwg

 

 

 

The end result should be a PDF package of the 3 paper spaces of drawing 200.dwg where the visibility state for blocks (UP, Down, Side) are set to 120 and 005

 

 

 

Message 6 of 13
philippe.leefsma
in reply to: inlinefg

Hi

 

We have multiple resources that deal with dynamic blocks and plotting on our blog, below are some of them, feel free to take a look if you need some more:

 

http://adndevblog.typepad.com/autocad/2012/08/how-to-access-and-modify-a-dynamicblockreference-prope...

 

http://adndevblog.typepad.com/autocad/2013/10/publishing-model-views-to-a-multi-sheet-dwfpdf.html

 

lhttp://adndevblog.typepad.com/autocad/2012/05/how-to-use-autodeskautocadpublishingpublisherpublishex...

 

Regards,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 7 of 13

inline, attached is quick bit i whipped up before i left work last night, changes the vis states of the blocks. This works on the assumption that all your blocks like this are setup in the same manner, with the vis states in the same order. What its doing, is selecting all blocks in the drawing, then filtering for dynamic blocks, then setting the vis property to a numbered state (in this example 1, being the second in the list, which starts at 0). No input from a form yet, but should get you started.(apologies for no code box, my browsers at work don't "see" the formatting bar). Tested from within acad 2014
Message 8 of 13

bah and of course the attachment fails.
Message 9 of 13

please send your code ... cant wait to test it
Message 10 of 13

had to go home to do this, but here you go. bah i forgot i had modified your 200 dwg, what i did was edit the visibility parameter in the blocks to set them apart from each other in this bit, as an idea to deal with multiple vis parameters (could also just rename the vis parameters themselves).:

                        'This is where you change states based on input
                        If prop.PropertyName = "Visibility" And prop.Description = "Exterior" Then
                            prop.Value = values(1)
                        End If
                        If prop.PropertyName = "Visibility" And prop.Description = "Interior" Then
                            prop.Value = values(2)
                        End If
                  

 whole code:

Imports System
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Runtime

Public Class Class1
    <CommandMethod("DBP")>
    Public Sub SetDynamicBlkProperty()
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor
        Using Tr As Transaction = db.TransactionManager.StartTransaction()
            Dim mytvs(0) As TypedValue
            mytvs(0) = New TypedValue(0, "Insert")
            Dim myfilter As New SelectionFilter(mytvs)
            Dim mypsr As PromptSelectionResult = ed.SelectAll(myfilter)
            If mypsr.Status = PromptStatus.OK Then
                Dim sset As SelectionSet = mypsr.Value
                For Each id As ObjectId In mypsr.Value.GetObjectIds
                    Dim bref As BlockReference = TryCast(Tr.GetObject(id, OpenMode.ForWrite), BlockReference)
                    Dim props As DynamicBlockReferencePropertyCollection = bref.DynamicBlockReferencePropertyCollection
                    For Each prop As DynamicBlockReferenceProperty In props
                        Dim values As Object() = prop.GetAllowedValues()
                        'This is where you change states based on input
                        If prop.PropertyName = "Visibility" And prop.Description = "Exterior" Then
                            prop.Value = values(1)
                        End If
                        If prop.PropertyName = "Visibility" And prop.Description = "Interior" Then
                            prop.Value = values(2)
                        End If
                    Next
                Next
            End If
            Tr.Commit()
        End Using
    End Sub
End Class

 

Message 11 of 13

please tell what i am doing wrong

in vb.net express 2012 i made a new project
copy and paste your code into mycommands.vb
build solution

open autocad 2014, open 200.dwg
netload the dll
run DBP

nothing is happening.
Message 12 of 13

its probably the mods I made to the 200 while try to differentiate between blocks. Remove this portion of code and try again.
And prop.Description = "Exterior" Then
                            prop.Value = values(1)
                        End If
                        If prop.PropertyName = "Visibility" And prop.Description = "Interior" Then
                            prop.Value = values(2)
Message 13 of 13

ah bugger it, don't do that, CHANGE it to this. It should then set all blocks with a vis parameter to the third one it the list.
If prop.PropertyName = "Visibility" Then
                            prop.Value = values(2)
                        End If

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