Using HOF Pattern for Transactions in Revit API
When reading the book “Functional Programming in C#”, I saw the concept of HOF. I felt that this method could be used to organize an extension method in the daily development process to achieve rapid calling of the program. Transaction function inherits from IDisposable We usually need to use using internal to operate Revit during development. Achieve automatic disassembly We need to create a generic function MTransaction and constrain it to the IDisposable interface Implement using keyword ...
Revit 二次开发 HOF 方式调用transaction
再看《C#函数式编程》一书的时候看到HOF的概念,感觉在日常开发的过程中可以使用此方式整理一个拓展方法,实现程序的快速调用。 Transaction函数继承自IDisposable 我们平时开发需要使用using内部对Revit进行操作。实现自动拆卸 我们需要创建一个泛型函数MTransaction并约束在IDisposable接口 在上述函数内部实现using关键词减少其他函数内部的反复调用,减少代码量降低耦合性 创建函数TransactionHelper对此放大引用封装,通过第三方调用中间函数即可完成调用 函数结构 123456789101112131415161718192021public static class MTransaction{ public static void Using<TDisp>(TDisp disposable, Action<TDisp> f) where TDisp : IDisposable { using (disposable) { ...
C++ 检测程序是否在运行
参考材料: Find process ID by name and inject to it. Simple C++ example.C++通过进程名获取进程句柄 函数原因主要是为了服务自动更新的函数,在检测到程序退出后执行后续函数。 使用第二个引用的时候报错,发现是for循环堆栈溢出,应该是字段判定函数的问题,导致每个程序的名称都判定正确,建议采取第一个网址中的内容。 code: 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667#pragma once#include <TlHelp32.h>class CheckApplication{public: CheckApplication();private: HANDLE getProcessHandle();public: int IsExit();private: const char* _Name ...
C++ Check if Process is Running
References: Find process ID by name and inject to it. Simple C++ example.C++ Get process handle by process name The function is mainly for the auto-update service, executing subsequent functions after detecting that the program has exited. When using the second reference, an error occurred. I found it was a stack overflow in the for loop, likely due to the field determination function, causing every program name to be judged correct. I recommend adopting the content from the first URL. code...
MFC 引用tinyxml,x64
想做一个使用ftp自动更新的模块,需要读取xml文档并于服务器的数据核对然后下载,本以为按照网上的教程可以解决但是中间还是遇到了许多问题,这里就记录一下步骤。 配置 Visual Studio 2022 tinyxml,下载链接:TinyXML 步骤 直接使用nuget下载tinyxml包最后会报错,原因是包里面是Win32编译的,所以最后会出现错误 根据下载的包,使用visual studio打开,并新建配置管理器,在里面创建x64配置,之后编译tinyxml项目文件,可以一次性将Debug,Release版本编译 生成后将以下几个文件放到文件夹中方便后期引用 4. 完成这两步之后,进入项目->属性->C\C++->附加包含目录,将.cpp,.h文件夹添加进去5. 我们还需要再头文件中引用lib文件不然将会报错 1#pragma comment(lib,"D:\\C++ Programming\\MFCAutoUpdateApplication\\src\\tinyxml\\lib\\debug\\tinyxml.lib") 下面是...
MFC Reference tinyxml, x64
I wanted to make a module that uses ftp for automatic updates. I needed to read xml documents and check against server data and then download. I thought I could solve it by following online tutorials, but I still encountered many problems in the middle. Here I record the steps. Configuration Visual Studio 2022 tinyxml, download link: TinyXML Steps Downloading the tinyxml package directly using nuget will eventually report an error, because the package is compiled for Win32, so an error will ...
Revit Auto Update - C++ FtpGetFiles()
For detailed explanation of FtpGetFiles() function see official documentation https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-ftpgetfilea Searching this function online found that introduction to this function is a bit scarce, so I put my successful execution code here hoping to help people learning together. Implementation method: Connect to server Get ftp connection handle Retrieve whether this file name exists in the project, if exists then download Use c++ to ...
Revit自动更新 - C++ FtpGetFiles()
FtpGetFiles()函数详细解释详见官方文档 https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-ftpgetfilea 网上搜这个函数发现这个函数介绍的有点少,所以将自己运行成功的代码放上来希望能够帮到一起学习的人。 实现方式: 链接服务器 获取ftp连接句柄 检索在项目中是否有此文件名称,如果存在则下载 使用c++ 操作ftp按照文档说法我们应当首先创建InternetOpen获取句柄,并将句柄传入函数InternetConnect函数,这一步与链接Mysql类似,获取了Connection句柄我们就可以使用Ftp的相关函数 123456789HINTERNET hint; HINTERNET hFtp; hint = InternetOpen(0, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0); if (hint == NULL) return -1; hFtp = InternetConnect(hint, ftpSvrIp.c_...
git 推送发现远程仓库地址错误
问题:项目上传时总是首先上传一个错误的仓库地址然后才是当前仓库地址问题原因: 由于不懂git导致设置了git的globalconfig在全局设置中添加了默认路径,导致每次上传都会上传一次全局路径导致出现错误。 解决办法使用命令git remote -v 可以看到一直有一个origin存在,使用git remote rm origin 删除发现始终删除不掉这个路径调用命令git config --global --list,可以发现global的配置与local的配置中出现了两个origin的地址看来是我们在全局变量中设置了一个仓库地址,导致每次上传都会首先上传这个地址,所以需要将这个地址删除输入命令~/.gitconfig,在弹出的编辑器中将[remote 'origin']删除即可删除全部路径,再次上传即可按照本地当前remote地址上传
git push found remote repository address error
Issue: Project upload always uploads to a wrong repository address first and then to the current repository addressReason: Due to not understanding git, set git’s globalconfig adding a default path in global settings, causing every upload to upload to the global path first, resulting in an error. SolutionUse command git remote -v to see that there is always an origin existing. Use git remote rm origin to delete but found that this path cannot be deleted.Call command git config --global --list...
Creating Multi-Version Revit Projects (Part 2)
https://www.cnblogs.com/ponus/p/11046624.html#!comments You can visit the original author’s blog and github by following the link above. Here, the problems encountered during project migration were recorded according to my own situation. Multi-version Project Construction After creating a new project, open the configuration manager to create compilation managers for multiple versions Unload the original project, open the *.csproj file, add nodes according to the version number, you can lim...
Revit二次开发 创建适配多版本项目(2)
https://www.cnblogs.com/ponus/p/11046624.html#!comments 可以按照上方链接地址访问原作者博客和github 此处按照自己的情况记录了一下项目迁移时遇到的问题 多版本项目搭建 创建新项目后,打开配置管理器创建多个版本的编译管理器 卸载原有项目,打开*.csproj文件,按照版本号添加节点,此处可以限定编译的framwork版本,此处的编译可以将’Any CPU’修改为x64 12<PlatformTarget>x64</PlatformTarget><TargetFrameworkVersion>v4.6</TargetFrameworkVersion> 依次将所有版本设置好之后可以继续在<ItemGroup>添加项目初始时需要添加的引用,此处我将Revit的ManagedMC3文件一起放进去了,因为会出现文件版本与RevitAPI版本不一致的情况,如果加密程序集将会报错 配置文件 12345678910111213141516171819202122...
Solved - Newly Created Elements Cannot Join Geometry in Revit API
Problem Scenario:Implement the function of blocking walls between beams. After I create a wall, I hope to connect the upper beam with the wall to present a better visual effect, but when I directly use joinGeometry after creating the wall, an error will be reported indicating that connection is not possible. Solution:Regenerate the document. Code: 123456789101112131415161718using (Transaction trans = new Transaction(doc,"Create Close Wall")) { trans.St...
Revit二次开发 新创建构件无法使用JoinGeometry等问题
问题场景:实现梁间墙封堵的功能,在我创建墙后希望将上部梁与墙连接处理,呈现更好的视觉效果,但是在我创建墙体后直接使用joinGeometry将会报错无法连接。解决办法:刷新一下文档 代码: 123456789101112131415161718using (Transaction trans = new Transaction(doc,"Create Close Wall")) { trans.Start(); //Wall Type var duplicate = CreateWallType(doc,wallWidth, $"FBQ - {Math.Round(wallWidth * 304.8)}"); var nWall = Wall.Create(doc, locationCurve, duplicate.Id, tLevel, value, 0, false,...
File Thread Occupation Issue
When checking if a file exists, if it does not exist and the command to create it is executed, subsequent operations will report a thread occupation error.Reason:The File.Create() command outputs a Stream, which needs to be closed, otherwise a thread occupation error will occur during runtime. 1234var stream = File.Create(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\RecheckModelUser.xml"); //...
File 文件线程占用的问题
在检索文件是否存在,如果不存在就创建这个命令的时候,后续的操作会报错线程占用原因:File.Create()命令会输出Stream,需要将流关闭,否则在运行期间会报错线程占用的问题 1234var stream = File.Create(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\RecheckModelUser.xml"); //此处需要首先关闭创建文件产生的stream流数据进程,否则将会报错线程占用 stream.Close();
In-Place Offset Scaling of Polyline Polygons
@[toc] Effect to be generatedThe basic principle of hanging pits or sumps is to generate a circle of walls along the outside of the slab boundary for blocking. Two methods for in-situ scaling of polyline polygonsOne is the method in Zhou Peide’s Computational Geometry - Algorithm Design and Analysis (Third Edition), and the other is the method cited from Calculation Method of Polyline Parallel Lines. Finally, the second method solved the project problem, but since I wrote both algorithms, I a...
折线多边形的原位放大
@[toc] 需要生成的效果吊坑或集水坑的基本原理是按照板边界外侧生成一圈墙体进行封堵 折线多边形的原位缩放两种办法一种是周培德的计算几何-算法设计与分析(第三版)中的办法另外一种是引用自折线平行线的计算方法的办法,最后第二种可以解决项目问题,但是两种算法都写了一遍就都分析一下,这种情况以后还会遇到方便回查。 6.10 多边形放大、缩小及移动 P309教材中记载了一种方法,通过封闭多边形内部的一个点向每个点做向量,并基于向量的值向外侧偏移指定距离实现偏移,此处需要计算的值 多边形内部点与边界点的向量 v 偏移值是两个平行线段的垂线距离所以遇到斜向线段时需要计算实际长度 c#实现12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091/// <summary>/// 偏移指定路径值...
Automatically Generate Section Stair Dimensions in Revit Secondary Development
ReferenceConversion of Revit Coordinates and Screen Coordinates PrerequisiteRecord of Issues and Solutions for Generation of Vertical Stair Dimensions in Revit Style ContentThe linked file above provides a method for converting screen coordinates to project coordinates. The principle is calculated by converting the proportion of the point in the screen and the boundary to the project, but the blogger’s method is only applicable to the XY plane case. If applied to a section, it cannot be satis...
Revit二次开发 自动生成剖面楼梯标注
引用revit坐标与屏幕坐标的转换 前置关于Revit中楼梯竖向标注的问题记录及生成方式的解决方案 样式 内容上面链接文件中提供了一种屏幕坐标转换为项目坐标的办法,原理时通过屏幕中的点与边界的比例换算到项目中计算得出,但是博主的方法只适用于XY平面的情况下,如果应用到剖面中就无法满足了,剖面会出现正交剖面及平行XY轴切割或是斜向剖面,所以下面的使用了博主的思想修改了一下方法 首先分析剖面视图,可以看作横向与纵向,纵向仅代表Z值,横向代表(X,Y)值,但是横向面会出现旋转偏移,可以把这个看作小时候转的皮蜻蜓一样,其次我们再Revit中看到的剖面视图其实是斜剖面对于屏幕的投影 我们获取到点击的屏幕坐标时,会获得屏幕的(X,Y)点,然后获得Revit工作空间的屏幕Rectangle,从而求出XY再空间中的比例 这里遇到两个情况,记录一下此处我最先想用UV换算,但是有个问题 无法获得View的BoudingBoxUV所以做吧 后来直接用比例计算,但还是斜剖面的问题,此时斜剖面两个ZoomCorns代表一个立方体所以无法直接通过比例换算 之后想通过Transform换算坐标,但是我们无法...










