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.
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
thank you gasty1001, can you help me identify the dynamic block visibility state and how to change this .net?
I will check into EULA
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
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
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/2013/10/publishing-model-views-to-a-multi-sheet-dwfpdf.html
Regards,
Philippe.
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
And prop.Description = "Exterior" Then prop.Value = values(1) End If If prop.PropertyName = "Visibility" And prop.Description = "Interior" Then prop.Value = values(2)
If prop.PropertyName = "Visibility" Then prop.Value = values(2) End If