Trang chủ
Giới thiệu
Tìm kiếm
1
Automation Studio 5.0 Full Crack
179 lượt xem
2
Harris's shock and vibration handbook
41 lượt xem
3
Các lệnh cad cơ bản cho người mới bắt đầu
24 lượt xem
4
Autodesk Autocad 2007 Full Crack
22 lượt xem
5
Một số lệnh thiết lập khung tên
22 lượt xem
Tài liệu học thuật
Phần mềm kỹ thuật
App script
Autodesk
Office
Matlab
Modelica
Đăng nhập
Tìm kiếm
Từ khóa tìm kiếm
autocad
inventor
ilogic
autolisp
mô phỏng
vba
cad/cam
model 3d
nosine
Đăng nhập
-
Đăng ký
Có
12
bài viết
Có
0
bình luận
Trang chủ
Danh mục
Tài liệu học thuật
Phần mềm kỹ thuật
App script
Autodesk
Office
Matlab
Modelica
Trang
Giới thiệu
Autodesk
(
6
bài viết)
2025-08-29
iLogic tự động lấy tên sheet idw chuyển thành ký hiệu bản vẽ và mô tả
LẤY KÝ HIỆU VÀ MÔ TẢ TỪ TÊN SHEETCode này chỉ áp dụng cho việc xuất bản vẽ trong inventor. Ví dụ: Sheet có tên là "00.00.00-Hình chung" thì sẽ split '-' nên chuỗi sẽ trở thành mảng có 2 phần tử đó là: "00.00.00" và 'Hình chung'.Dim sheetName As String Dim parts() As String Dim sheetCode As String = "" Dim sheetDesc As String = "" ' Lấy tên sheet hiện tại sheetName = ThisDrawing.ActiveSheet.Name ' Tách chuỗi theo dấu "-" parts = Split(sheetName, "-") ' Kiểm tra xem có đủ 2 phần không If parts.Length >= 2 Then sheetCode = parts(0).Trim() sheetDesc = parts(1).Trim() ' Loại bỏ phần ":số" ở cuối SheetDesc nếu có Dim colonIndex As Integer = sheetDesc.LastIndexOf(":") If colonIndex > 0 Then Dim afterColon As String = sheetDesc.Substring(colonIndex + 1).Trim() ' Kiểm tra xem phần sau dấu ":" có phải là số không Dim tempNumber As Integer If Integer.TryParse(afterColon, tempNumber) Then sheetDesc = sheetDesc.Substring(0, colonIndex).Trim() End If End If Else sheetCode = sheetName.Trim() sheetDesc = "" End If ' Gán giá trị vào Custom Properties iProperties.Value("Custom", "SheetCode") = sheetCode iProperties.Value("Custom", "SheetDesc") = sheetDesc ' Cập nhật document ThisApplication.ActiveDocument.Update() ' Hiển thị kết quả MessageBox.Show("Sheet Code: " & sheetCode & vbCrLf & "Sheet Description: " & sheetDesc, "Result")XUẤT BẢN VẼ HÀNG LOẠT DƯỚI DẠNG PDF VÀ DWG :Sử dụng API của Inventor: TranslatorAddIn6 - pdf và TranslatorAddIn2 - dwgImports System.Windows.Forms Imports System.IO Sub Main() ' Chọn tính năng xuất Dim choice As String = InputBox("Chọn tính năng:" & vbCrLf & _ "1 - Xuất bản vẽ với định dạng PDF" & vbCrLf & _ "2 - Xuất bản vẽ với định dạng AutoCAD DWG" & vbCrLf & _ "Nhập 1 hoặc 2:", "Xuất bản vẽ", "1") If choice = "" Then Exit Sub ' User cancelled Dim exportPDF As Boolean = (choice = "1") Dim exportDWG As Boolean = (choice = "2") If Not exportPDF And Not exportDWG Then MessageBox.Show("Lựa chọn không hợp lệ!") Exit Sub End If Dim outputPath As String = "" Dim resolution As String = "" Dim dwgVersion As String = "" Dim strIniFile As String = "P:\_auto-test\conf.ini" ' Mặc định file .ini ' Yêu cầu thông tin bổ sung dựa trên lựa chọn If exportPDF Then resolution = InputBox("Chọn độ phân giải (150/200/300/400/600/720/1200/2400/4800):", "Xuất bản vẽ với định dạng PDF", "1200") If resolution = "" OrElse Not {"150", "200", "300", "400", "600", "720", "1200", "2400", "4800"}.Contains(resolution) Then MessageBox.Show("Độ phân giải không hợp lệ! Vui lòng chọn từ danh sách.") Exit Sub End If outputPath = InputBox("Nhập đường dẫn thư mục để lưu file:", "Xuất bản vẽ với định dạng PDF", "P:\_auto-test\pdf\") ElseIf exportDWG Then dwgVersion = InputBox("Chọn phiên bản AutoCAD DWG (2010/2013/2018):", "Xuất bản vẽ với định dạng AutoCAD DWG", "2013") If dwgVersion = "" OrElse Not {"2010", "2013", "2018"}.Contains(dwgVersion) Then MessageBox.Show("Phiên bản DWG không hợp lệ! Vui lòng chọn từ danh sách.") Exit Sub End If strIniFile = InputBox("Nhập đường dẫn file .ini (mặc định: P:\_auto-test\conf.ini, đảm bảo có 'ALL SHEETS=No'):", "Xuất bản vẽ với định dạng AutoCAD DWG", "P:\_auto-test\conf.ini") If strIniFile = "" Then Exit Sub ' User cancelled outputPath = InputBox("Nhập đường dẫn thư mục để lưu file:", "Xuất bản vẽ với định dạng AutoCAD DWG", "P:\_auto-test\cad\") End If If outputPath = "" Then Exit Sub ' User cancelled If Not outputPath.EndsWith("\") Then outputPath = outputPath & "\" ' Tạo thư mục nếu chưa tồn tại If Not System.IO.Directory.Exists(outputPath) Then System.IO.Directory.CreateDirectory(outputPath) End If ' Lấy document hiện tại Dim drawDoc As DrawingDocument = ThisApplication.ActiveDocument ' Lưu sheet hiện tại để có thể quay lại Dim originalSheet As Sheet = drawDoc.ActiveSheet ' Đếm số sheet và log tên sheet Dim totalSheets As Integer = drawDoc.Sheets.Count Dim sheetNames As String = "Danh sách sheet:" & vbCrLf For Each sheet As Sheet In drawDoc.Sheets sheetNames = sheetNames & Sheet.Name & vbCrLf Next MessageBox.Show("Tổng số sheet: " & totalSheets & vbCrLf & sheetNames, "Thông tin sheet") Dim processedSheets As Integer = 0 Dim exportedIdentifiers As New List(Of String) ' Chỉ dùng cho DWG để phát hiện trùng lặp Try ' Duyệt qua từng sheet For Each sheet As Sheet In drawDoc.Sheets ' Activate sheet hiện tại Sheet.Activate() ' Cập nhật Custom Properties cho sheet hiện tại UpdateSheetProperties(Sheet.Name) ' Cập nhật document drawDoc.Update() ' Tạo tên file từ sheet name Dim fileName As String = GetSafeFileName(Sheet.Name) If exportPDF Then ' Export PDF tự động ExportToPDF(drawDoc, outputPath, fileName, resolution) ElseIf exportDWG Then Dim dwgPath As String = outputPath & fileName & ".dwg" ' Split filename để lấy unique identifier Dim parts() As String = fileName.Split("_"c) Dim uniqueIdentifier As String = "" If parts.Length >= 3 Then uniqueIdentifier = parts(0) & "_" & parts(1) ' e.g., "00.00_1" Else uniqueIdentifier = fileName ' Fallback End If ' Kiểm tra trùng lặp If exportedIdentifiers.Contains(uniqueIdentifier) Then MessageBox.Show("Tệp DWG đã tồn tại cho sheet với mã: " & uniqueIdentifier & vbCrLf & "Sheet: " & Sheet.Name, "Cảnh báo trùng lặp - Bỏ qua") Continue For End If ' Export DWG ExportToDWG(drawDoc, outputPath, fileName, dwgVersion, strIniFile) ' Thêm vào list exportedIdentifiers.Add(uniqueIdentifier) End If processedSheets = processedSheets + 1 ' Hiển thị tiến độ ThisApplication.StatusBarText = "Đang xử lý sheet " & processedSheets & "/" & totalSheets & ": " & Sheet.Name Next ' Quay lại sheet ban đầu originalSheet.Activate() ' Hiển thị thông báo hoàn thành Dim exportedFilesList As String = "" If exportDWG Then exportedFilesList = "Các tệp DWG đã xuất (mã duy nhất):" & vbCrLf & String.Join(vbCrLf, exportedIdentifiers) End If If exportPDF Then MessageBox.Show("Đã hoàn thành xuất " & totalSheets & " sheet thành PDF!" & vbCrLf & _ "Đường dẫn: " & outputPath, "Xuất bản vẽ với định dạng PDF") Else MessageBox.Show("Đã hoàn thành xuất " & processedSheets & " sheet thành DWG!" & vbCrLf & _ "Đường dẫn: " & outputPath & vbCrLf & exportedFilesList, "Xuất bản vẽ với định dạng AutoCAD DWG") End If Catch ex As Exception MessageBox.Show("Lỗi: " & ex.Message, "Lỗi") Finally ' Xóa thông báo trạng thái ThisApplication.StatusBarText = "" End Try End Sub ' Hàm cập nhật Custom Properties cho sheet Sub UpdateSheetProperties(sheetName As String) Dim parts() As String Dim sheetCode As String = "" Dim sheetDesc As String = "" ' Tách chuỗi theo dấu "-" parts = Split(sheetName, "-") ' Kiểm tra xem có đủ 2 phần không If parts.Length >= 2 Then sheetCode = parts(0).Trim() sheetDesc = parts(1).Trim() ' Loại bỏ phần ":số" ở cuối SheetDesc nếu có Dim colonIndex As Integer = sheetDesc.LastIndexOf(":") If colonIndex > 0 Then Dim afterColon As String = sheetDesc.Substring(colonIndex + 1).Trim() ' Kiểm tra xem phần sau dấu ":" có phải là số không Dim tempNumber As Integer If Integer.TryParse(afterColon, tempNumber) Then sheetDesc = sheetDesc.Substring(0, colonIndex).Trim() End If End If Else sheetCode = sheetName.Trim() sheetDesc = "" End If ' Gán giá trị vào Custom Properties iProperties.Value("Custom", "SheetCode") = sheetCode iProperties.Value("Custom", "SheetDesc") = sheetDesc End Sub ' Hàm tạo tên file an toàn (loại bỏ ký tự không hợp lệ) Function GetSafeFileName(fileName As String) As String Dim invalidChars() As Char = IO.Path.GetInvalidFileNameChars() For Each invalidChar As Char In invalidChars fileName = fileName.Replace(invalidChar, "_") Next Return fileName End Function ' Hàm export PDF sử dụng PDF Translator Add-In Sub ExportToPDF(drawDoc As DrawingDocument, outputPath As String, fileName As String, resolution As String) Try Dim pdfPath As String = outputPath & fileName & ".pdf" ' Tìm PDF Add-In Dim pdfAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") If pdfAddIn IsNot Nothing Then Dim context As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext context.Type = IOMechanismEnum.kFileBrowseIOMechanism Dim options As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap ' Check whether the translator has 'SaveCopyAs' options If pdfAddIn.HasSaveCopyAsOptions(drawDoc, context, options) Then ' Options for drawings... options.Value("All_Color_AS_Black") = 0 options.Value("Remove_Line_Weights") = 0 options.Value("Vector_Resolution") = Integer.Parse(resolution) options.Value("Sheet_Range") = PrintRangeEnum.kPrintCurrentSheet options.Value("Custom_Begin_Sheet") = 0 options.Value("Custom_End_Sheet") = 0 options.Value("Include_Dimensions") = 0 options.Value("Include_Notes") = 0 options.Value("Include_Borders") = 0 End If Dim dataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium dataMedium.FileName = pdfPath ' Publish document pdfAddIn.SaveCopyAs(drawDoc, context, options, dataMedium) Else MessageBox.Show("Không tìm thấy PDF Add-In!", "Lỗi") End If Catch ex As Exception MessageBox.Show("Lỗi khi xuất PDF cho sheet: " & fileName & vbCrLf & _ "Lỗi: " & ex.Message, "Lỗi PDF") End Try End Sub ' Hàm export DWG sử dụng INI file Sub ExportToDWG(drawDoc As DrawingDocument, outputPath As String, fileName As String, dwgVersion As String, strIniFile As String) Try Dim dwgPath As String = outputPath & fileName & ".dwg" ' Tìm DWG Add-In Dim dwgAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}") If dwgAddIn IsNot Nothing Then Dim context As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext context.Type = IOMechanismEnum.kFileBrowseIOMechanism Dim options As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap ' Check whether the translator has 'SaveCopyAs' options If dwgAddIn.HasSaveCopyAsOptions(drawDoc, context, options) Then options.Value("Export_Acad_IniFile") = strIniFile ' Sử dụng file INI options.Value("Export_Acad_Version") = dwgVersion ' Override phiên bản nếu cần options.Value("AllSheets") = "No" ' Đảm bảo chỉ xuất sheet hiện tại options.Value("Sheet_Range") = PrintRangeEnum.kPrintCurrentSheet ' Safeguard thêm End If Dim dataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium dataMedium.FileName = dwgPath ' Export document dwgAddIn.SaveCopyAs(drawDoc, context, options, dataMedium) Else MessageBox.Show("Không tìm thấy DWG Add-In!", "Lỗi") End If Catch ex As Exception MessageBox.Show("Lỗi khi xuất DWG cho sheet " & fileName & ": " & ex.Message, "Lỗi DWG") End Try End Sub
29-08-2025
5
0
0
2025-08-02
lisp cập nhật các trường dữ liệu trong nhiều layout
Áp dụng cho các trường bảng tạo bởi lệnh TABLE và trường dữ liệu tạo bởi lệnh ATT . Dùng để thay đổi dữ liệu trong tất cả các layout (thực hiện hàng loạt).;; Cập nhật trường toàn bộ bảng trong các layout (defun c:table_update ( / layname ) (vl-load-com) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) ;; Lặp qua tất cả layout (vlax-for lay (vla-get-Layouts doc) (setq layname (vla-get-Name lay)) (if (not (wcmatch (strcase layname) "*MODEL*")) ; bỏ qua Model nếu muốn (progn (vla-put-ActiveLayout doc lay) (command "_.UPDATEFIELD" "_ALL" "") ) ) ) ;; Cuối cùng về lại layout ban đầu (princ "\nĐã cập nhật tất cả Field ở mọi layout.") (princ) )
02-08-2025
10
0
0
2025-07-25
lisp tạo thước đo góc
Thực ra cái này thì bạn có thể hoàn toàn tạo được bằng lệnh ARRAYPOLAR nhưng việc đánh số khá mất thì giờ; vậy nên bạn có thể tham khảo lisp này.(defun c:angle360 ( / pt r ang p x y txt) (setq pt (getpoint "\nChọn tâm đường tròn: ")) ; Tâm đường tròn (setq r (getreal "\nNhập bán kính đặt số: ")) ; Khoảng cách ra ngoài (setq ang 0) ; Bắt đầu từ góc 0 độ (repeat 36 (setq p (* pi (/ ang 180.0))) ; Chuyển độ sang radian (setq x (+ (car pt) (* r (cos p)))) (setq y (+ (cadr pt) (* r (sin p)))) (setq txt (strcat "GOC=" (itoa ang))) (command "TEXT" (list x y) "0" "5" "0" txt) (setq ang (+ ang 10)) ; Tăng lên 10 độ mỗi bước ) (princ "\nĐã đánh số đủ số góc quanh đường tròn.") (princ) )Để sử dụng lisp này, bạn cần tạo thêm 1 file txt ngang hàng với file này có nội dung dạng:GOC=0 GOC=10 GOC=20 GOC=30 GOC=40 GOC=50 GOC=60 ... GOC=350Cuối cùng, thực hiện lệnh angle360 để vẽ thước đo góc 360deg
25-07-2025
11
0
0
2025-07-25
lisp đổi tên block cho tất cả các block có cùng tên
Lưu code sau vào file .lsp => sau đó vào autocad nhập lệnh APPLOAD với chế độ always để load lisp này vào.Để sử dụng, vui lòng nhập lệnh block_rename , hoặc bạn có thể đổi tên hàm thành chuỗi dễ nhớ hơn.;; Rename block (defun c:block_rename (/ find replace blocks blkName newname) ;; Input (setq find (getstring "\nNhập tiền tố ban đầu (vd: EL_TE-): ")) (setq replace (getstring "\Nhập tiền tố sau khi thay thế (vd: ME_TE-): ")) ;; Duyệt tất cả block definitions (setq blocks (tblnext "BLOCK" T)) (while blocks (setq blkName (cdr (assoc 2 blocks))) ;; Bỏ qua block ẩn hoặc xref (if (and (/= (logand (cdr (assoc 70 blocks)) 1) 1) (wcmatch blkName (strcat find "*"))) (progn ;; str_replace (setq newname (vl-string-subst replace find blkName)) ;; Gọi lệnh RENAME của autocad (princ (strcat "\nRenaming: " blkName " -> " newname)) (command "_.RENAME" "Block" blkName newname) ) ) ;; next block (setq blocks (tblnext "BLOCK")) ) (princ "\nHoàn tất.") (princ) )
25-07-2025
11
0
0
2025-07-25
iLogic tính một số thông số đặc trưng hình học
Dim doc = ThisDoc.Document Dim oCD As ComponentDefinition = doc.ComponentDefinition Dim oCommandMgr As CommandManager = ThisApplication.CommandManager ' Chọn mặt phẳng Dim oFace As Face = oCommandMgr.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Chọn mặt phẳng phẳng") If oFace Is Nothing Then Exit Sub ' Tạo sketch trên mặt phẳng đã chọn Dim oSk As PlanarSketch = oCD.Sketches.Add(oFace) oSk.Edit() ' Thực thi lệnh ProjectCutEdgesCmd oCommandMgr.ControlDefinitions("SketchProjectCutEdgesCmd").Execute() ' Lấy profile và tính diện tích, các momen quán tính Dim oProfile As Profile = oSk.Profiles.AddForSolid Dim dArea_cm2 As Double = oProfile.RegionProperties.Area Dim adPrincipalMoments(2) As Double oProfile.RegionProperties.PrincipalMomentsOfInertia( _ adPrincipalMoments(0), _ ' Ix (Moment quán tính quanh trục X) adPrincipalMoments(1), _ ' Iy (Moment quán tính quanh trục Y) adPrincipalMoments(2)) ' Ixy (Moment quán tính chéo) ' Tìm giới hạn x và y từ các điểm sketch Dim minX As Double = Double.MaxValue Dim maxX As Double = Double.MinValue Dim minY As Double = Double.MaxValue Dim maxY As Double = Double.MinValue For Each pt As SketchPoint In oSk.SketchPoints If pt.Geometry.X < minX Then minX = pt.Geometry.X If pt.Geometry.X > maxX Then maxX = pt.Geometry.X If pt.Geometry.Y < minY Then minY = pt.Geometry.Y If pt.Geometry.Y > maxY Then maxY = pt.Geometry.Y Next ' Tính tọa độ trọng tâm (centroid) và chuyển đổi sang mm Dim centroid As Point2d = oProfile.RegionProperties.Centroid Dim cX_cm As Double = centroid.X Dim cY_cm As Double = centroid.Y Dim cX_mm As Double = cX_cm * 10 Dim cY_mm As Double = cY_cm * 10 ' Tính diện tích Dim dArea_mm2 As Double = dArea_cm2 * 100 ' cm² → mm² ' Tính khoảng cách từ trọng tâm đến điểm xa nhất theo trục X và Y Dim maxDistX As Double = Math.Max(Math.Abs(maxX - cX_cm), Math.Abs(minX - cX_cm)) * 10 ' Đoạn đường xa nhất theo trục X (mm) Dim maxDistY As Double = Math.Max(Math.Abs(maxY - cY_cm), Math.Abs(minY - cY_cm)) * 10 ' Đoạn đường xa nhất theo trục Y (mm) ' Tính các momen quán tính theo mm² và mm⁴ Dim Ix_mm4 As Double = adPrincipalMoments(0) * 10000 ' cm⁴ → mm⁴ Dim Iy_mm4 As Double = adPrincipalMoments(1) * 10000 ' cm⁴ → mm⁴ ' Tính momen kháng uốn Wx và Wy Dim Wx_mm3 As Double = Ix_mm4 / maxDistY ' mm³ Dim Wy_mm3 As Double = Iy_mm4 / maxDistX ' mm³ ' Hiển thị kết quả trong hộp thoại MsgBox ("Diện tích: " & Round(dArea_mm2, 2) & " mm²" & vbCrLf & _ "Tọa độ trọng tâm: (" & Round(cX_mm, 2) & ", " & Round(cY_mm, 2) & ") mm" & vbCrLf & _ "Khoảng cách từ trục trung hòa:" & vbCrLf & _ "- Tới điểm xa nhất theo trục X: " & Round(maxDistX, 2) & " mm" & vbCrLf & _ "- Tới điểm xa nhất theo trục Y: " & Round(maxDistY, 2) & " mm" & vbCrLf & _ "Ix: " & Round(Ix_mm4, 2) & " mm⁴" & vbCrLf & _ "Iy: " & Round(Iy_mm4, 2) & " mm⁴" & vbCrLf & _ "Wx: " & Round(Wx_mm3, 2) & " mm³" & vbCrLf & _ "Wy: " & Round(Wy_mm3, 2) & " mm³", vbInformation, "iLogic Đặc trưng hình học:")
25-07-2025
7
0
0
1
2