How to set the visstate of a dynamic block through a script - not through a lisp

How to set the visstate of a dynamic block through a script - not through a lisp

timothy_crouse
Collaborator Collaborator
358 Views
3 Replies
Message 1 of 4

How to set the visstate of a dynamic block through a script - not through a lisp

timothy_crouse
Collaborator
Collaborator

Does anyone know of a command to set the visstate of a dynamic block through a script?

 

I can select the block as follows in the script:

 

SSX{enter}

{enter}

B

"block name with spaces"{enter}

{enter} ;; it may or may not appear as selected

 

this will prove it is selected

ERASE{enter}

PREVIOUS{enter}

 

Once selected is there any way to set the visstate through the script?

 

Or perhaps have the script run a lisp that sets the visstate.  I am interested in carrying this out via a script as it is to be part of an automation batch script

 

Thanks in Advance

-Tim C.

0 Likes
359 Views
3 Replies
Replies (3)
Message 2 of 4

paullimapa
Mentor
Mentor

assuming you can run lisp then read up on this related thread

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/repeat-insert-dynamic-block-and-choo...


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 4

Sea-Haven
Mentor
Mentor

"Automation batch script" there is no problem in calling a lisp program in a script, so add the variables to the link lisp code when using in a script.

 

 

open dwg1
(load "mywindows")
(mywindows "window1" "Casement")
Close Y

 

0 Likes
Message 4 of 4

randyorten7707
Community Visitor
Community Visitor

Setting the visibility state (VisState) of a dynamic block through a script can vary depending on the software you're using. If you're not using LISP, you might be working with a different scripting language or software environment.

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

namespace DynamicBlockVisibility
{
public class Commands
{
[CommandMethod("SetVisState")]
public void SetVisibilityState()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;

// Get the block name and visibility state from the user
PromptStringOptions opts = new PromptStringOptions("\nEnter the block name: ");
PromptResult res = ed.GetString(opts);
if (res.Status != PromptStatus.OK) return;
string blockName = res.StringResult;

opts.Message = "\nEnter the visibility state: ";
res = ed.GetString(opts);
if (res.Status != PromptStatus.OK) return;
string visibilityState = res.StringResult;

using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
if (bt != null && bt.Has(blockName))
{
ObjectId btrId = bt[blockName];
BlockTableRecord btr = tr.GetObject(btrId, OpenMode.ForWrite) as BlockTableRecord;
if (btr != null && btr.IsDynamicBlock)
{
foreach (ObjectId objId in btr)
{
if (objId.ObjectClass.IsDerivedFrom(RXClass.GetClass(typeof(BlockReference))))
{
BlockReference blkRef = tr.GetObject(objId, OpenMode.ForWrite) as BlockReference;
if (blkRef != null && blkRef.IsDynamicBlock)

on the sublime by longinus
{
// Set the visibility state
blkRef.DynamicBlockReferencePropertyCollection.SetVisibilityState(visibilityState);
blkRef.RecordGraphicsModified(true);
}
}
}
}
}
tr.Commit();
}
}
}
}

0 Likes