Accessing the active space or layout in an AutoCAD drawing using .NET

 

This question was asked as comment to a previous post by har!s:

Thanks a lot for the code. I have yet to see 2008 and MultiLeader. But I presume that it works on both Model and paper spaces. In that case, what is the best method to make the operation space independent? i.e., it should work on active space irrespective of whether it's model or paper. I think this will be generally applicable to almost all the entity creations.

The question is very valid and does indeed apply to a lot of entity creation - and other - activities. Most of the time I simply show how to open the modelspace in my code, for example:

  Document doc =

    Application.DocumentManager.MdiActiveDocument;

  Editor ed = doc.Editor;

  Database db = doc.Database;

  Transaction tr =

    db.TransactionManager.StartTransaction();

  using (tr)

  {

    BlockTable bt =

      (BlockTable)tr.GetObject(

        db.BlockTableId,

        OpenMode.ForRead

      );

    BlockTableRecord btr =

      (BlockTableRecord)tr.GetObject(

        bt[BlockTableRecord.ModelSpace],

        OpenMode.ForWrite

      );

    // ...

  }

The key statement here is at the end, where we use GetObject() to open the BlockTableRecord to which we want to (for example) append an entity. The form we use is:

  bt[BlockTableRecord.ModelSpace]

Breaking this down: we're actually looking up the ObjectId of the BlockTableRecord with the name of "*MODEL_SPACE", which is the string stored in the static ModelSpace property of the BlockTableRecord class.

Here are a few different options for what we might do here:

  1. Use either BlockTableRecord.ModelSpace or BlockTableRecord.PaperSpace, if we know that we want to access either of these containers (the current approach).
  2. Use foreach() on the BlockTable to iterate through the various BlockTableRecords: you can open each one using GetObject() and check the IsLayout property to find those that are either modelspace or paperspace layouts.
  3. Use db.CurrentSpaceId to open the currently active space in that particular database.

Option 3 is really the answer to this question, which makes the code like this:

  Document doc =

    Application.DocumentManager.MdiActiveDocument;

  Editor ed = doc.Editor;

  Database db = doc.Database;

  Transaction tr =

    db.TransactionManager.StartTransaction();

  using (tr)

  {

    BlockTable bt =

      (BlockTable)tr.GetObject(

        db.BlockTableId,

        OpenMode.ForRead

      );

    BlockTableRecord btr =

      (BlockTableRecord)tr.GetObject(

        db.CurrentSpaceId,

        OpenMode.ForWrite

      );

    // ...

  }

内容概要:本文详细介绍了文生视频大模型及AI人应用方案的设计与实现。文章首先阐述了文生视频大模型的技术基础,包括深度生成模型、自然语言处理(NLP)和计算机视觉(CV)的深度融合,以及相关技术的发展趋势。接着,文章深入分析了需求,包括用户需求、市场现状和技术需求,明确了高效性、个性化和成本控制等关键点。系统架构设计部分涵盖了数据层、模型层、服务层和应用层的分层架构,确保系统的可扩展性和高效性。在关键技术实现方面,文章详细描述了文本解析与理解、视频生成技术、AI人交互技术和实时处理与反馈机制。此外,还探讨了数据管理与安全、系统测试与验证、部署与维护等重要环节。最后,文章展示了文生视频大模型在教育、娱乐和商业领域的应用场景,并对其未来的技术改进方向和市场前景进行了展望。 适用人群:具备一定技术背景的研发人员、产品经理、数据科学家以及对AI视频生成技术感兴趣的从业者。 使用场景及目标:①帮助研发人员理解文生视频大模型的技术实现和应用场景;②指导产品经理在实际项目中应用文生视频大模型;③为数据科学家提供技术优化和模型改进的思路;④让从业者了解AI视频生成技术的市场潜力和发展趋势。 阅读建议:本文内容详尽,涉及多个技术细节和应用场景,建议读者结合自身的专业背景和技术需求,重点阅读与自己工作相关的章节,并结合实际项目进行实践和验证。
### 获取用于访问API的认证密钥 #### 使用跨集群API密钥进行身份验证 对于某些特定环境下的API访问,如本地集群向远程集群发起请求时,可以采用跨集群API密钥来进行安全的身份验证。这种情况下,API密钥需由远程集群管理员预先创建好。之后,在每次从本地集群发送至远程集群的请求里都应附带该API密钥以便完成必要的鉴权流程[^1]。 #### 创建API Keys的具体操作路径 为了获得API keys,用户可以通过指定平台上的相应界面来实现这一目标。具体而言,可以在页面左侧菜单找到名为“API keys”的选项卡(亦可通过直接输入网址`https://platform.deepseek.com/api_keys`进入),随后点击界面上提供的“创建 API key”按钮即可启动新密钥的生成过程[^2]。 #### Python环境下利用Session维持会话状态 当涉及到基于Python的应用程序与外部API交互时,除了简单的单次请求外,还经常需要保持一段时间内的连续访问权限。此时可借助于requests库中的Session对象,它允许开发者在一个持续的时间窗口内重复使用相同的认证凭证而无需每次都重新提交完整的授权信息。一旦检测到服务器返回的状态码为401且错误原因指向令牌失效,则表明当前使用的OAuth token已过期,应当立即采取措施更新token以恢复正常的API调用能力[^3]。 #### 实施API签名机制增强安全性 针对那些对数据传输有着更高安全保障需求的服务接口来说,仅依靠单一形式的API key可能不足以完全抵御潜在的安全威胁。因此引入了一种更为严谨的做法——即所谓的API签名认证方式。在此模式下,客户端不仅要在每一次HTTP请求中携带一对公私钥组合(通常称为AK/SK),而且还要按照既定算法计算出本次请求的数据摘要作为附加参数一同传递给服务端。如此一来即使中途有人截获了网络包也无法轻易伪造合法的请求,从而大大提高了整个系统的抗攻击性能[^4]。 ```python import hmac import hashlib from datetime import datetime, timedelta import requests def create_api_signature(access_key_id, secret_access_key, method, endpoint, params=None): timestamp = (datetime.utcnow() + timedelta(seconds=60)).isoformat() string_to_sign = f"{method}\n{endpoint}\n{timestamp}" if params is not None: sorted_params = "&".join([f"{k}={v}" for k, v in sorted(params.items())]) string_to_sign += f"\n{sorted_params}" signature = hmac.new( bytes(secret_access_key, "utf-8"), msg=bytes(string_to_sign, "utf-8"), digestmod=hashlib.sha256, ).hexdigest() headers = { "X-API-Key": access_key_id, "X-Signature": signature, "Date": timestamp, } return headers access_key_id_example = "<your-access-key-id>" secret_access_key_example = "<your-secret-access-key>" headers = create_api_signature( access_key_id_example, secret_access_key_example, "GET", "/example-endpoint" ) response = requests.get("http://api.example.com/example-endpoint", headers=headers) print(response.text) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值